Type classes problem: Could not deduce ...

dirk.buehler@student.uni-tuebingen.de dirk.buehler@student.uni-tuebingen.de
Mon, 10 Mar 2003 13:24:14 +0100


trying to compile the following program

  class ClassA a where
	foo :: a -> Int

  class ClassA a => ClassB b a where
	toA :: b -> a

  test :: (ClassB b a) => b -> Int
  test x = 
	let y = toA x in
	let z = foo y in

I get a compilation error:

    Could not deduce (ClassB b a1) from the context (ClassB b a)
    Probable fix:
	Add (ClassB b a1) to the type signature(s) for `test'
    arising from use of `toA' at TestTypeClasses.hs:12
    In a pattern binding: toA x

Can anybody explain the problem to me or suggest workarounds? Adding (ClassB b a1) to the context does not solve the problem, it just generates an error of the same sort. 

Any hints are appreciated. 

Cheers, dirk 

Werden Sie kreativ! Bei WEB.DE FreeMail heisst es jetzt nicht nur schreiben,
sondern auch gestalten. http://freemail.web.de/features/?mc=021142