[erlang-questions] specs for fixed length lists

Joe Armstrong erlang@REDACTED
Mon Jul 9 23:54:11 CEST 2012


I find this very strange it violates the principle of least
astonishment. I expect the elements of a list to have the same type,
but I expect the elements of a tuple to have different types, which is
why map is defined over
lists and not tuples.

And yes you can do it, but that it not to say that you should do it.

/Joe

On Mon, Jul 9, 2012 at 10:54 PM, Lukas Larsson
<lukas@REDACTED> wrote:
> Writing a generic tuple:map/2 would not be that hard either:
>
> map(F, Tuple) ->
>    map(F, Tuple, size(Tuple)).
>
> map(F,Tuple,1) ->
>    setelement(1,Tuple,F(element(1,Tuple)));
> map(F,Tuple,N) ->
>    map(F,setelement(N,Tuple,F(element(N,Tuple))),N-1).
>
> It's not very pretty, or efficient, but it gets the job done.
>
> Lukas
>
> On Mon, Jul 9, 2012 at 9:59 PM, Daniel Goertzen
> <daniel.goertzen@REDACTED> wrote:
>>
>> On Sun, Jul 8, 2012 at 1:22 AM, <ok@REDACTED> wrote:
>>>
>>> I'm with /Joe on this one.  There aren't all _that_ many
>>> list operations that make sense on tuples, and
>>>     map4(F, {A,B,C,D}) -> {F(A), F(B), F(C), F(D)}.
>>> is easy enough to define.  Perhaps the code needs turning
>>> inside out.
>>>
>>
>> Thanks for the idea; my functional instincts are still developing.  I will
>> go with this approach since my sequence size really is only 4.
>>
>> Dan.
>>
>> _______________________________________________
>> erlang-questions mailing list
>> erlang-questions@REDACTED
>> http://erlang.org/mailman/listinfo/erlang-questions
>>
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://erlang.org/mailman/listinfo/erlang-questions



More information about the erlang-questions mailing list