[Haskell-beginners] Confused by type constraints

Guy guytsalmaves-h at yahoo.com
Fri Jun 3 15:04:05 CEST 2011


I have some code resembling

class Foo f where
	foo :: a -> f a

data Bar f a = Foo f => Bar {bar :: f a}

instance Foo (Bar f) where
	foo a = Bar $ foo a

GHC insists on Foo f => in the instance declaration. However, the definition of Bar guarantees that this will always be 
the case. Why do I have to state this explicitly?




More information about the Beginners mailing list