[Haskell-cafe] List containing different types but all implementing the same class

Bo Herlin bo at gcab.net
Fri Apr 8 12:31:22 EDT 2005


Hi everyone. Being new to Haskell I wonder how I can make a list contain 
different types but all implementing the same class, like this:

data X = X
data Y = Y

class Z a where f :: a -> Int

instance Z X where f x = 0
instance Z Y where f y = 1

test1 :: Z a => [a]
test1 = [X,Y]

test2 = map f test1

Is it possible to make this work?

/Bo Herlin


More information about the Haskell-Cafe mailing list