[Haskell-cafe] Rank2Types and pattern matching
Yves Parès
limestrael at gmail.com
Sat Jul 3 19:24:17 EDT 2010
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?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20100703/59f6c01f/attachment.html
More information about the Haskell-Cafe
mailing list