[erlang-questions] specs for fixed length lists

Daniel Goertzen daniel.goertzen@REDACTED
Fri Jul 6 18:28:33 CEST 2012


While working with lists of fixed length, I noted that type specification
for such lists are conspicuously missing.  For example, the following does
not work...

-spec get_buttons() -> {ok, [boolean(), boolean(), boolean(), boolean()]}.

Is there some sneaky way to make this go?  Now I know you would normally
use a tuple in this situation, but I will be using the lists module to
process this data so I want to stick with lists.

I would love to see something like this for list specification...


  List :: list(Type)                        %% Proper list ([]-terminated)
+       | list(Type, Length)                %% Proper list of fixed size
+       | tlist(TList)                      %% Proper list specified like a
tuple
        | improper_list(Type1, Type2)       %% Type1=contents,
Type2=termination
        | maybe_improper_list(Type1, Type2) %% Type1 and Type2 as above

  Tuple :: tuple()                          %% stands for a tuple of any
size
        | {}
        | {TList}

  TList :: Type
        | Type, TList


Thanks,
Dan.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20120706/cb77569c/attachment.htm>


More information about the erlang-questions mailing list