[英]Difference between binary, String.t, char_list and [char] in a typespec
Which are the different between binary, String.t, char_list, [char] etc when defining a typespec? 定义typespec时,binary,String.t,char_list,[char]等之间有何区别?
@spec method(binary) :: binary
and 和
@spec method(String.t) :: String.t
Are they equivalent? 它们相等吗? Doc says:
Doc说:
String.t
is the same as binary
, see its definition here . String.t
与binary
相同,请参见此处的定义。
char_list
is more than a plain list of chars. char_list
不仅仅是一个普通的char列表。 It's defined in the unicode
module in Erlang to be: 在Erlang的
unicode
模块中定义为:
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. 因此,它既包含正确的列表,也包含不正确的列表,并且该列表可以包含字符,二进制文件或字符列表或空列表。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.