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.