[erlang-questions] spec declaration for single list parameter with fixed size

Jesper Louis Andersen jesper.louis.andersen@REDACTED
Sun Jul 3 12:20:15 CEST 2011


On Sun, Jul 3, 2011 at 11:58, Michael Richter <ttmrichter@REDACTED> wrote:
> On 3 July 2011 16:10, Roberto Ostinelli <roberto@REDACTED> wrote:
>>
>> a very stupid spec declaration question. how can you declare the specs of
>> a function which has a single list with multiple arguments?
>>
>> For instance, consider this function:
>
>
>>
>> myfun([One, Two]) ->
>

This is better since you then have a product type rather than a
recursive type on lists. It is much simpler to work with from a typing
perspective. Also note that you would not easily be able to type
["hello", 5] in a statically typed language without resorting to
either some kind of type tagging, polymorphic variants or existential
types.

My advice would be to alter the structure of the function such that it
is easier to type. It tends to be safer from a programming perspective
as well.

-- 
J.



More information about the erlang-questions mailing list