
Brian Hulley wrote:
Brian Hulley wrote:
f,g :: (forall a. CC a => a Int) -> Int -- not allowed
delete the "not allowed" comment ;-) It's not so simple as I'd thought so I'd be interested to know the reason for $ making a difference too.
Actually I must undelete my "not allowed" comment above: you are trying to use existential types which are not supported in Haskell yet. You can simulate an existential by wrapping it in a single constructor data type eg: data Foo a = forall b. CC b => Foo (b a) Rewriting your example to use this simulation of existentials, everything works: class CC b data Foo a = forall b. CC b => Foo (b a) f :: Foo a -> Int f _ = 3 data A1 c = A1 c data A2 c = A2 c instance CC A1 instance CC A2 p = f (Foo (A1 3)) q = f (Foo (A2 3)) g x = f $ x The reason it works is that the Foo constructor keeps track of which particular 'b' has been used for any particular 'Foo a', so that class methods of the correct 'b' can be used inside the body of 'f'. Regards, Brian.