type [string()] 是否覆盖空列表?
Does type [string()] cover empty list?
当定义一个字符串列表但也可以是空列表的类型时,我是否必须像这样定义这两种情况:
-type my_type() :: [string()] | [].
或者这样就够了:
-type my_type() :: [string()].
是的,[string()]
包含空列表,因此如果您想包含空列表,使用 -type my_type() :: [string()].
就可以了。
Because lists are commonly used, they have shorthand type notations. The types list(T)
and nonempty_list(T)
have the shorthands [T]
and [T,...]
, respectively. The only difference between the two shorthands is that [T]
can be an empty list but [T,...]
cannot.
当定义一个字符串列表但也可以是空列表的类型时,我是否必须像这样定义这两种情况:
-type my_type() :: [string()] | [].
或者这样就够了:
-type my_type() :: [string()].
是的,[string()]
包含空列表,因此如果您想包含空列表,使用 -type my_type() :: [string()].
就可以了。
Because lists are commonly used, they have shorthand type notations. The types
list(T)
andnonempty_list(T)
have the shorthands[T]
and[T,...]
, respectively. The only difference between the two shorthands is that[T]
can be an empty list but[T,...]
cannot.