
Hi Benjamin, [] has the type [a] because there is no constraint on what the type of its elements could be, hence it is polymorphic. ([]) is actually the parenthesised expression for [], in the same way any expression e == (e). Haskell does have a unit type: Prelude> :t () () :: () I guess this is analogue of the empty tuple to the empty list. One element tuples are not allowed - they are themselves expressions. The unit type is like the Null construct in other languages. Kind regards, Chris. On Wed, 24 Sep 2008, 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:
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....
-- Benjamin L. Russell
_______________________________________________ Beginners mailing list Beginners@haskell.org http://www.haskell.org/mailman/listinfo/beginners