[erlang-questions] A modest proposal to eliminate tuples

Dmitry Kolesnikov dmkolesnikov@REDACTED
Wed Aug 27 20:37:15 CEST 2014


Hello,

There is a different memory model for tuples and lists. Tuples are more efficient to access random element while list requires iteration. I would not be brave to drop them completely. 

BTW, when I am writing a program in other languages, I am so missing tuples...

Best Regards,
Dmitry
>-|-|-(*>

> On 27 Aug 2014, at 21:21, Chris Pacejo <colanderman@REDACTED> wrote:
> 
> Tuples are clearly unnecessary and a wart in Erlang's design.
> Consider all the operations tuples provide:
> 
> Construction: X = {A,B,C}
> Destruction: {A,B,C} = X
> Pattern matching: case X of {foo,B,C} -> ... end
> 
> Note now that these operations are provided equally by lists:
> 
> Construction: X = [A,B,C]
> Destruction: [A,B,C] = X
> Pattern matching: case X of [foo,B,C] -> ... end
> 
> And note that lists provide the additional functionality of indexing
> and consing, which tuples do not provide.
> 
> Clearly, using tuples instead of lists provides no benefit, and to
> simplify the language they should be deprecated in OTP 18, and removed
> by OTP 19.  To support this transition, a compiler option can be
> provided to maintain the ill-conceived tuple notation for legacy code;
> may I suggest +distinguish_homogenous_and_heterogenous_collections.
> 
> Now, surely detractors will claim that the distinction between tuples
> and lists signals programmer intent, permits bytecode optimization,
> and enables rich typechecking in Dialyzer.  I claim these purported
> benefits are bollocks.  I, and no doubt others, routinely find the
> need to iterate over tuple elements, and to store unrelated data
> together in a single list.  Anyone who claims that such things are not
> necessary clearly has not ever written a complex program.  (I suspect
> anyone who thinks structurally-typed records and key-value maps serve
> different purposes falls into this group.)
> 
> I hope you all agree, and that we can look forward to a future Erlang
> supporting lists and maps as its sole data constructors.
> 
> - Chris P
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://erlang.org/mailman/listinfo/erlang-questions



More information about the erlang-questions mailing list