[Haskell-cafe] And another basic typing question -- empty list

Adam Wyner adam at wyner.info
Fri Sep 16 10:02:44 EDT 2005


I have some questions about using the empty list in Hugs.  In June 2001, 
was raised as a bug in hugs (see Hugs-Bugs Archives).  References 
therein to
a bug list on S. Thompson's pages come up a dead end.  I haven't found 
any follow
up or solution to this discussed.  I would particularly like to use an 
empty list
in the Trex module of Hugs.

Suppose I have two expressions:

emptyListA = null

emptyListB = []

emptyListA is apparently a function from empty lists to Bool.
I would have thought that emptyListB would just be the empty
list and output it as such.

 > :t emptyListA

emptyListA :: [a] -> Bool

 > emptyListA []

The problem is that there is no "show" function for
emptyListB, which is just []

 > emptyListB
ERROR - Cannot find "show" function for:
*** Expression : emptyListB
*** Of type    : [a]

What I would like, simply is:


More to my purpose, I would like to use the empty list as a value
of a record in Trex.  For instance, while the first example below
gives a good result, the second example has no "show" function.
Looking at the Trex module, it would seem that there is a show
function for the empty list (?? but frankly, I have never touched
this area of haskell, so I haven't given it much thought).

Sample command line I/O.

 > (a = 'a', b = [2])
(a = 'a', b = [2])

 > (a = 'a', b = [])
ERROR - Cannot find "show" function for:
*** Expression : (a = 'a', b = [])
*** Of type    : Rec (a :: Char, b :: [a])

Clearly, the problem is the empty list labelled b.

What I want is the following sort of result:

 > (a = 'a', b = [])
(a = 'a', b = [])

Further along, what I want is to have values for the field labelled b
to be lists which contain something.  So, in one case, the value is
[], while in another it is [2], say.  Moreover, I want to define
a type which has a label with values of type lists.  That is, I want to 
a record something like Rec (a :: Char, b :: List).
However, List is not a basic data type.  And in any case, the values of 
cannot show empty lists.  I'm unsure whether Trex or any record type can 
handle this.

Here are some examples.
The following is OK.

type TestList01 = Rec (a :: Char, b :: [Char])

testList01 :: TestList01
testList01 = (a = 'a', b = "b")

Input and output are:
 > testList01
(a = 'a', b = "b")

ComplexActions01> :t (a = 'a', b = "b")
(a = 'a', b = "b") :: Rec (a :: Char, b :: [Char])

But the following type is uninterpretable:

type TestList02 = Rec (a :: Char, b :: [])

ERROR "ComplexActions01.lhs":196 - Illegal type "[]" in constructor

Suggestions about how to treat empty lists?

Adam Wyner

More information about the Haskell-Cafe mailing list