I got confused in the next 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 I try 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 is the function good
typecheck, but ghc refuses to accept the function bad
? And what can I do to make the latest version work? As far as I can see, both examples should be equivalent.
source
share