[erlang-questions] specs for fixed length lists

Joe Armstrong erlang@REDACTED
Sat Jul 7 12:15:18 CEST 2012


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
>



More information about the erlang-questions mailing list