[Haskell] Why Does This Typecheck?

Dominic Steinitz dominic.steinitz at blueyonder.co.uk
Tue Dec 21 16:52:05 EST 2004


Main> :t baz
baz :: Foo a => Char' a -> a
Main> :t v
v :: Char' BW
Main> :t test1
test1 :: Bool
Main> :t (baz v)
baz v :: Foo a => a

Why doesn't the typechecker unify Char' BW with a and therefore the type 
of test1 = baz v becomes Char' BW resulting in a type error by not being 
able to unify Char' BW with Char' Bool?

Dominic.

class Foo a where
    foo :: Char -> a

instance Foo Bool where
    foo 'F' = False
    foo 'T' = True

data BW = Black | White
    deriving Show

instance Foo BW where
    foo 'B' = Black
    foo 'W' = White

type Char' a = Char

baz :: Foo a => Char' a -> a
baz x = foo x

v :: Char' BW
v = 'B'

test1 :: Bool
test1 = baz v


More information about the Haskell mailing list