[erlang-questions] specs for fixed length lists

Richard Carlsson carlsson.richard@REDACTED
Sun Jul 8 21:40:35 CEST 2012


On 07/08/2012 08:14 PM, Anthony Ramine wrote:
> Doesn't this spec mean "a list of atom() or list of integer() and
> empty list"? I don't see any nonempty constraint in this type.
>
> Regards,
>
> -- Anthony Ramine

Yes, you're right. I abused the notation in the same way that Tony's 
original question was stated. In the type notation, "|" just means type 
union, so "[T1 | T2]" means "list of T1|T2", and not "list starting with 
T1 followed by a tail of T2". Basically, there are no individual cons 
cells in the type notation.

     /Richard


> Le 7 juil. 2012 à 21:53, Richard Carlsson
> <carlsson.richard@REDACTED> a écrit :
>
>> On 2012-07-07 13:57, Tony Rogvall wrote:
>>> Try this:
>>>
>>> -type buttons() :: [boolean() | [boolean() | [boolean() |
>>> [boolean() | []]]]].
>>
>> You certainly can _write_ it like that, just like you can write
>> "1+1" instead of "2". To a tool like Dialyzer, it will still just
>> be interpreted as a (nonempty) list of boolean(). The exact number
>> of elements is not tracked. And if you for example try to say
>> "[atom() | [integer() | []]]", it will just be the same as saying
>> "nonempty list of atom()|integer()" - the order of occurrence of
>> the element types is also not part of the list type.
>>
>> /Richard _______________________________________________
>> erlang-questions mailing list erlang-questions@REDACTED
>> http://erlang.org/mailman/listinfo/erlang-questions





More information about the erlang-questions mailing list