[Haskell-cafe] Type Constraints on Data Constructors

Guy guytsalmaves-h at yahoo.com
Wed Jun 8 20:45:56 CEST 2011

{- continuing discussion from beginners@ -}

I have code such as

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 that I put Foo f => on the instance declaration, even though the constructor for Bar implies this.

Is there any reason why GHC cannot infer this constraint from the Bar constructor? One issue raised in the beginners 
thread is that
undefined :: Bar f a
is not Foo f, but as undefined cannot be evaluated, this would not appear to be a problem.

More information about the Haskell-Cafe mailing list