[Haskell-beginners] type constructors

Michael P Mossey mpm at alumni.caltech.edu
Sat Aug 1 13:44:49 EDT 2009


I was playing around with type constructors and I wrote this:

data Foo a b = Foo1 [a]
              | Foo2 (a -> b)

t3 = Foo1 [1, 2, 3]

I wanted to see what ghci thought the type of t3 was. Essentially, it's data 
that doesn't use all of the type variables. So this ran fine, and

*Main> :t t3
t3 :: Foo Integer b

Wow! The data exists but it doesn't have a "complete type" so to speak. This 
worked, too:

f3 (Foo1 xs) = length xs

*Main> f3 t3
3

This is surprising to a conventional programmer. But does this naturally relate 
to other features of Haskell. Perhaps laziness? (I.e. data of type Foo doesn't 
always need a type b so it just doesn't have one until it needs one.)

Thanks,
Mike



More information about the Beginners mailing list