[Haskell-beginners] Why is there no notion of a one-tuple (e.g., a '([])' as opposed to a '[]') in Haskell?

Philippa Cowderoy flippa at flippac.org
Wed Sep 24 08:36:20 EDT 2008


On Wed, 24 Sep 2008, Benjamin L.Russell wrote:

> >Haskell doesn't have a notion of a one-element tuple.
> 
> Why not?

Because that would've required clearing special syntactic space for it, 
and in most cases it's not semantically significant at all. The exception 
is when you put something strict in it.

> It seems that a tuple is similar to a list, except that the
> elements need not be all of the same type, and that a tuple, unlike a
> list, cannot be extended.  Yet:
> 
> Prelude> :type []
> [] :: [a]
> 
> and 
> 
> Prelude> :type [[]]
> [[]] :: [[a]]
> 
> so the types of the empty-list '[]' and the one-element list
> containing the empty-list '[[]]' are different.
> 
> Forgive me if I am missing something, but something about this
> asymmetry bothers me....
> 

A one-element list will normally have a different type to the empty list 
because now we know what it's a list /of/ - the a in [a] has been 
substituted for [b] (or rather, a /new/ a) because we know we're looking 
at a list of lists of something.

There are no one-tuples, so (x) is just x in parentheses and ([]) is just 
[].

-- 
flippa at flippac.org

Performance anxiety leads to premature optimisation


More information about the Beginners mailing list