[erlang-questions] Tuple Matching Question
Jared Kofron
jared.kofron@REDACTED
Tue Dec 9 20:18:08 CET 2014
Hi Santosh,
No, you can't pattern match on the head of a tuple, because a tuple doesn't
have a head in the same sense that a list does.
The size of the tuple is part of its type - {A,B,C} is of type {any(),
any(), any()}, whereas [A,B,C] has type [any()]. If I remove the first
element of [any()], I get something of type [any()], whereas if I remove
the first element of {any(), any()}, it's of type {any()}.
So there's no cons operator for tuples in the same way that there is for
lists, because adding/removing some element of a tuple actually changes its
type.
That's how I think of it, anyhow.
On Tue Dec 09 2014 at 11:04:32 AM Imants Cekusins <imantc@REDACTED> wrote:
> Hi Santosh,
>
> element(1,{a,b,c}).
> returns a
>
> http://www.erlang.org/doc/reference_manual/data_types.html#id64155
> _______________________________________________
> 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/20141209/a30e226a/attachment.htm>
More information about the erlang-questions
mailing list