[phobos] Fwd: Tuple, TypeTuple, tupleof etc

Shin Fujishiro rsinfu at gmail.com
Tue Oct 12 09:30:29 PDT 2010


Here's my thoughts.

Tuple should be kept as-is.  But TypeTuple and tupleof should be
renamed meta.Sequence and fieldsof, respectively.  These names are
better because they reflect facts more precisely.  Let's see why I
think so.

std.typecons' Tuple should be kept.  A Tuple instance packs several
run-time values in a single entity - it's really what called a tuple.
So, the name should be kept as is.

On the other hand, TypeTuple should be renamed meta.Sequence due to
its peculiar nature...  (a) It can contain anything but run-time values,
and (b) it automatically expands by itself.  You can even use
TypeTuples for filling array literals and function arguments.  They're
more like flat sequences of compile-time entities than packed tuples.

Also, the built-in tupleof property should be renamed.  It's just a
misnomer...  It presents a run-time sequence of the all fields of an
aggregate object, not a tuple of the aggregate. (what's that?)  The
name should be more intuitive and straightforward: fieldsof.

To sum up, I think we should take these actions:

 1.  Leave Tuple as is;
 2.  Deprecate TypeTuple with meta.Sequence; and
 3.  Deprecate tupleof with fieldsof.

The proposed nomenclature reflects the facts around the "three tuples"
more precisely, and there's no confusion.  What do you think?


P.S.  Ah... maybe meta.Sequence can be replaced with the hot craze
"tuple literals" if they can contain types and symbols.  Sure, I'll be
happy if so!  (But they should be called sequence literals... ;-))


Shin

Shin Fujishiro <rsinfu at gmail.com> wrote:
> It's about the messy situation around tuple nomenclature in Phobos:
> 
>  - TypeTuple can contain values too
>  - Tuple is different from TypeTuple
>  - tupleof is not a Tuple but a TypeTuple consisting of values
> 
> Note also that "Tuple" has packed semantics and "TypeTuple" has
> expanded semantics.  The two are really different in many aspects.
> What to do with them?
> 
> 
> Shin
> 
> On July 6, bearophile posted to the newsgroup:
> 
> > You have a "tupleof" struct attribute that gives a TypeTuple, and it
> > can contain values too and not just types, and then you have a Tuple in
> > Phobos that is something similar, but not exactly the same as, a
> > TypeTuple. You can return a Tuple but not a TypeTuple. All this is
> > messy, D newbies will have troubles. Having two slightly different
> > kinds of tuples in a language is bad, but mixing their names in those
> > ways is even worse.
> > 
> > In my dlibs1 what's called Tuple is named Record and what's named
> > TypeTuple is named Tuple, this is better because a record is quite
> > similar to a struct (as named in Pascal-like languages too), while a
> > Tuple is named tuple in the language too.  The name "Record" is bad for
> > this purpose because while it's structurally a struct, from an usage
> > point of view it's more like a mathematical tuple.
> > 
> > In the end I still think "Record" and "Tuple" are better names, despite
> > their faults. Please think of the newbies :-) Can those two names in
> > Phobos2 be changed?
> 
> http://www.digitalmars.com/d/archives/digitalmars/D/Tuple_TypeTuple_tupleof_etc_113005.html


More information about the phobos mailing list