[Haskell-beginners] one element tuple

Daniel Fischer daniel.is.fischer at web.de
Sat Jun 12 16:23:24 EDT 2010


On Saturday 12 June 2010 22:09:48, bitur mail wrote:
> Hello,
>
> This is a dumb question but ...
>
> I'm just starting with the book Real World Haskell, and in chapter 2 it
> mentions that "Haskell doesn't have a notion of a one-element tuple".
>
> I am confused by this because I type, for example, (143), into the
> interpreter and it does not complain. What does Haskell consider (143)
> to be?

An ordinary value, enclosed in parentheses.

Prelude> :t (143)
(143) :: (Num t) => t
Prelude> (143) == 143
True

That's different to e.g. Python:

>>> x = (3,)
>>> len(x)
1
>>> type(x)
<type 'tuple'>
>>> x == 3
False

which has a notion of 1-tuples having a type different from the type of 
their components.

>
> Thanks :)
> DG



More information about the Beginners mailing list