
Hi, I was playing around after getting the new O'Reilly book with lists and their operators! Not sure what the below actually means? Prelude> [] : [] [[]] it :: [[a]] (Got :set +t on ) I thought the first argument of ':' must be an element, so is the empty list an element of the same type of the contents of the empty list? Yours confused Paul :-)

Hi Paul, You wrote:
Prelude> [] : [] [[]] it :: [[a]] I thought the first argument of ':' must be an element, so is the empty list an element of the same type of the contents of the empty list?
There is not just one "empty list". The symbol [] is actually polymorphic - it can refer to the empty list in [a], for any type a. In particular, "a" can itself be a list type. So [] : [] is an element of [[a]], the type of list of lists of a, for any type a. Hope this helps, Yitz

On 2009 Jan 5, at 15:40, Paul Johnston wrote:
Hi, I was playing around after getting the new O'Reilly book with lists and their operators! Not sure what the below actually means?
Prelude> [] : [] [[]] it :: [[a]]
(Got :set +t on )
I thought the first argument of ':' must be an element, so is the empty list an element of the same type of the contents of the empty list?
(:) :: a -> [a] -> [a] In this case the first argument is an empty list (type forall a. [a]) and the second must therefore be an empty list of lists (type forall a. [[a]]). Hence the result is also of type forall a. [[a]] (with all the `a's unified). -- brandon s. allbery [solaris,freebsd,perl,pugs,haskell] allbery@kf8nh.com system administrator [openafs,heimdal,too many hats] allbery@ece.cmu.edu electrical and computer engineering, carnegie mellon university KF8NH
participants (3)
-
Brandon S. Allbery KF8NH
-
Paul Johnston
-
Yitzchak Gale