[erlang-questions] specs for fixed length lists

Tony Rogvall tony@REDACTED
Sun Jul 8 11:48:28 CEST 2012


On 7 jul 2012, at 21:53, Richard Carlsson wrote:

> 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.
> 
But you can not _write_ (why do you use underscore before and after write? ) things like 
-spec get_buttons1() -> {ok, [boolean(),boolean(),boolean(),boolean()]}.
Because you will get a syntax error!. 
Why is the "dotted pair" notation supported if it does not work ?
It can not be harder to support then supporting pairs ? (For the record I do think it could be a bit harder :)

BTW 
	The 1+1 = 2 example was totally silly in my opinion.

/Tony


>    /Richard
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://erlang.org/mailman/listinfo/erlang-questions

"Installing applications can lead to corruption over time. Applications gradually write over each other's libraries, partial upgrades occur, user and system errors happen, and minute changes may be unnoticeable and difficult to fix"



-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20120708/a3ccc166/attachment.htm>


More information about the erlang-questions mailing list