# 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
|   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
|=20
|   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':
|                     x <- p
|                     let MkThread p' =3D k x
|                     p')
|=20