[Haskell-cafe] history of tuples vs pairs

Brent Yorgey byorgey at seas.upenn.edu
Wed Jun 25 14:24:57 EDT 2008


On Wed, Jun 25, 2008 at 07:50:08PM +0200, Niels Aan de Brugh wrote:
> On Wed, 2008-06-25 at 16:50 +0200, Conal Elliott wrote:
> > I have a foggy memory that early ML had only binary pairing, nesting
> > for n-tuples.  Can anyone confirm this memory.  If so, does anyone
> > remember the rationale for going to n-tuples?  Performance, perhaps?
> 
> ???What is the difference between a list build up of Cons and a "tuple"
> made out of pairs? I think the latter wouldn't really add anything new.

The difference is that all the elements of a list must be the same
type, whereas nested tuples could have elements of any type.  For
example,

  (True, (6, 'c')) :: (Bool, (Int, Char))

and there is no corresponding three-element list.  However, you're
right in noting the similarity between lists and nested tuples -- in
fact, this is exactly how lists are implemented in lisp (which is
where we get the tern 'cons').

> 
> A question of my own: is there much difference between e.g.
>   data MyData = MyData Int Bool Char
> and
>   type MyData = (Int, Bool, Char)
> other than the syntax of course?

Conceptually, there is not much difference; these types are clearly
isomorphic.  Practically speaking, there are differences other than
just the syntax.  For example, in Haskell 98 you are not allowed to
make class instances for type synonyms.  Another big difference is
that this:

  type MyData = (Int, Bool, MyData)

is illegal, whereas this:

  data MyData = MyData Int Bool MyData

is perfectly fine.

-Brent


More information about the Haskell-Cafe mailing list