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

Brent Yorgey byorgey at seas.upenn.edu
Wed Sep 24 09:20:17 EDT 2008


On Wed, Sep 24, 2008 at 09:08:49PM +0900, Benjamin L.Russell wrote:
> I'm having difficulty in understanding the following behavior:
> 
> In GHCi:
> 
> Prelude> :type []
> [] :: [a]
> 
> but:
> 
> Prelude> :type ([])
> ([]) :: [a]
> 
> I.e., the types of both the empty-list '[]' and the one-tuple
> containing the empty-list '[]' are '[a]' (a list of a generic type
> variable).
> 
> According to "Chapter 2. Types and Functions" (see
> http://book.realworldhaskell.org/read/types-and-functions.html) of
> Real World Haskell (beta) (see
> http://book.realworldhaskell.org/beta/), 
> 
> >Haskell doesn't have a notion of a one-element tuple.
> 
> Why not?  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:

Note that it would be really annoying to have parentheses create a
one-tuple.  That would lead to such joyous fun as

  > 1 + (2 + 3)

  <interactive>:1:0:
      No instance for (Num (t))
        arising from a use of `+' at <interactive>:1:0-8
      Possible fix: add an instance declaration for (Num (t))
      In the expression: 1 + (2 + 3)
      In the definition of `it': it = 1 + (2 + 3)

(artist's conception).  So some other syntax would be needed, but as
Philippa points out, that would be a lot of syntactic heaviness for
not much benefit.  Python actually does have one-tuples: you create a
one-tuple containing, say, the number 3 by writing:

  (3,)

Ugly!

In the end, there's no *theoretical* reason why Haskell
doesn't have one-tuples: this is one of the few places in the language
design where practical concerns won out over theoretical.

-Brent


More information about the Beginners mailing list