brain explosion in polymorphic state monad

Simon Peyton-Jones simonpj@microsoft.com
Fri, 11 Oct 2002 09:00:39 +0100


Use 'case'.  Instead of

|                let MkStateT m2 =3D k a
|                m2 s1 )

say
		case k a of
		  MkStateT m2 -> m2 s1

Simon

| -----Original Message-----
| From: mathieu [mailto:tenfingers@ifrance.com]
| Sent: 10 October 2002 21:42
| To: ghc users
| Subject: brain explosion in polymorphic state monad
|=20
| Hello,
|=20
| I am trying to define a polymorphic state monad using glasgow
extensions and I got a
| brain explosion of ghc when i try to compile it.
|=20
| Here is the code :
|=20
| newtype StateT s m a =3D MkStateT (s -> m (a, s))
|=20
| instance Monad m =3D> Monad (StateT s m) where
|   return x =3D MkStateT (\s -> return (x, s))
|   MkStateT m1 >>=3D k =3D
|     MkStateT
|     (\s0 -> do (a, s1) <- m1 s0
|                let MkStateT m2 =3D k a
|                m2 s1 )
|=20
| data Thread a =3D forall b . MkThread (StateT (Thread b) [] a)
|=20
| instance Monad Thread where
|   return =3D MkThread . return
|   MkThread p >>=3D k =3D MkThread ( do x <- p
|                                    let MkThread p' =3D k x
|                                    p' )
|=20
| I got this error :
|    My brain just exploded.
|     I can't handle pattern bindings for existentially-quantified
constructors.
|     In the binding group
|         MkThread p' =3D k x
|     In the first argument of `MkThread', namely
|         `(do
|             x <- p
|             let MkThread p' =3D k x
|             p')'
|     In the definition of `>>=3D':
|         MkThread (do
|                     x <- p
|                     let MkThread p' =3D k x
|                     p')
|=20
| How can i define (>>=3D) for my thread monad ?
|=20
| Thanks in advance for any piece of advice,
| Mathieu
|=20
| --
| There are only 10 types of people in the world:
| Those who understand binary and those who don't.
| _______________________________________________
| Glasgow-haskell-users mailing list
| Glasgow-haskell-users@haskell.org
| http://www.haskell.org/mailman/listinfo/glasgow-haskell-users