Which are the different between binary, String.t, char_list, [char] etc when defining a typespec?
@spec method(binary) :: binary
and
@spec method(String.t) :: String.t
Are they equivalent? Doc says:
String.t
is the same as binary
, see its definition here.
char_list
is more than a plain list of chars. It's defined in the unicode
module in Erlang to be:
maybe_improper_list(char() | unicode_binary() | charlist(),
unicode_binary() | [])
So it includes both proper and improper lists and the list can contain chars, binaries, or charlists or the empty list.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With