[Haskell-cafe] Re: Fwd: Is () a 0-length tuple?

Jon Fairbairn jon.fairbairn at cl.cam.ac.uk
Sun Nov 8 05:14:07 EST 2009

"Pasqualino \"Titto\" Assini" <tittoassini at gmail.com> writes:

> The syntax is similar, but what else is?

What would you expect from an empty tuple?

(a,b,c) has a constructor function p3 a b c = (a,b,c) and three
destructor functions s3_1 (a,b,c) = a, s3_2 (a,b,c) = b and s3_3 (a,b,c)=c

(a,b) has a constructor function p2 a b = (a,b) and two destructor functions
s2_1 (a,b) = a and s2_2 (a,b) = b

(a) has a constructor function p1 a = (a) and one destructor function 
s1_1 a = a

() has a constructor function p0 = () and zero destructor functions.

> In JavaScript there is a "null" value, that is the only value of the
> null type.

I'm not sure that Javascript is a suitable place to get intuitions for
Haskell (null type would seem more like empty than single), but anyway,
the thing is that the sole (non-bottom) value of the /unit/ type is the
same as the empty tuple¹.

> Isn't () the same thing?  The only value of the unary type?

The "empty" type in Haskell would be (forall a.a) which has no
non-bottom values.

[1] Aside: I wanted haskell to share the same type for all empty values
(ie lists would have been symmetric unions of pairs with the unit type
List t = (t,List t) || ()), but that didn't fit with algebraic datatypes
so the design went a different way.
Jón Fairbairn                                 Jon.Fairbairn at cl.cam.ac.uk

More information about the Haskell-Cafe mailing list