When defining a type which will be a list of strings but can also be an empty list, do I have to define both cases like this:
-type my_type() :: [string()] | [].
or is this enough:
-type my_type() :: [string()].
Yes, [string()]
includes the empty list so using -type my_type() :: [string()].
is fine if you want to include empty lists.
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.