
Hello everybody, I'm trying to implement the type protection used by ST to prevent a monad from returning a certain type. There's my code: import Control.Monad.Identity newtype SomeMonad s a = SomeMonad { unSome :: Identity a } deriving (Monad) newtype SomeType s = SomeType Int runSomeMonad :: (forall s. SomeMonad s a) -> a runSomeMonad (SomeMonad x) = runIdentity x And when compiled, I got this error: phantom.hs:10:14: Couldn't match expected type `forall s. PwetMonad s a' against inferred type `PwetMonad s a1' In the pattern: PwetMonad x In the definition of `runPwetMonad': runPwetMonad (PwetMonad x) = runIdentity x But when I change line 10 to: runSomeMonad x = runIdentity . unSome $ x then it works, so obviously, the trouble is about pattern matching. What was I doing wrong?