Error when ($) is used, but no error without
Brian Hulley
brianh at metamilk.com
Thu Apr 27 00:22:03 EDT 2006
Robin Bate Boerop wrote:
> This code compiles properly (with -fglasgow-exts on GHC 6.4.1):
>
> class CC a
> type C x = CC a => a x
> f, g :: C a -> Int
> f _ = 3
> g x = f x
>
> But, this code:
>
> class CC a
> type C x = CC a => a x
> f, g :: C a -> Int
> f _ = 3
> g x = f $ x -- the only change
>
> gives this error:
>
> Inferred type is less polymorphic than expected
> Quantified type variable `a' escapes
> Expected type: a a1 -> b
> Inferred type: C a1 -> Int
> In the first argument of `($)', namely `f'
> In the definition of `g': g x = f $ x
>
> What's going on here?
I think the type declaration is actually equivalent to:
type C x = forall a. CC a => a x
so that you are declaring:
f,g :: (forall a. CC a => a Int) -> Int -- not allowed
instead of:
f,g :: forall a. (CC a => a Int ->Int)
More information about the Glasgow-haskell-users
mailing list