Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
在定义将是字符串列表但也可以是空列表的类型时,我是否必须像这样定义两种情况:
-type my_type() :: [string()] | [].
或者这就足够了:
-type my_type() :: [string()].
是的,[string()]包括空列表,因此-type my_type() :: [string()].如果您想包括空列表,则可以使用。
[string()]
因为列表是常用的,所以它们具有速记类型符号。类型list(T)和分别nonempty_list(T)具有简写[T]和[T,...]。两个速记之间的唯一区别是[T]可以是空列表但[T,...]不能。
list(T)
nonempty_list(T)
[T]
[T,...]
资源