[erlang-questions] specs for fixed length lists

Daniel Goertzen daniel.goertzen@REDACTED
Sat Jul 7 15:03:19 CEST 2012


But tuples lack things like lists:map() and lists:foreach().  If there were
such functions for tuples, I would agree with you and just use tuples.

Dan.

On Sat, Jul 7, 2012 at 5:15 AM, Joe Armstrong <erlang@REDACTED> wrote:

> I don't understand.
>
> Lists are intended as containers for a variable number of terms. Tuples are
> intended as a container for a fixed number of terms. Not using lists and
> tuples
> as they are intended will just lead to confusion.
>
> /Joe
>
> On Fri, Jul 6, 2012 at 6:28 PM, Daniel Goertzen
> <daniel.goertzen@REDACTED> wrote:
> > 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.
> >
> >
> > _______________________________________________
> > erlang-questions mailing list
> > erlang-questions@REDACTED
> > http://erlang.org/mailman/listinfo/erlang-questions
> >
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20120707/c5ac2992/attachment.htm>


More information about the erlang-questions mailing list