I am confused about the following program.
{-# LANGUAGE RankNTypes #-}
newtype A a = A ( forall f. Applicative f => f a )
good :: a -> A a
good x = A $ pure $ x
bad :: a -> A a
bad x = A . pure $ x
When trying to compile, I get this error message, complaining about bad
:
Couldn't match type `f0 a'
with `forall (f :: * -> *). Applicative f => f a'
Expected type: f0 a -> A a
Actual type: (forall (f :: * -> *). Applicative f => f a) -> A a
Relevant bindings include
x :: a (bound at huh.hs:8:6)
bad :: a -> A a (bound at huh.hs:8:1)
In the first argument of `(.)', namely `A'
In the expression: A . pure
Why does the function good
typecheck, while ghc refuses to accept the function bad
? And what could I do to make the latter version work? As far as I can see, both examples should be equivalent.