[Haskell-cafe] Monad woes

Levi Greenspan greenspan.levi at googlemail.com
Sun Aug 23 12:38:33 EDT 2009

On Sun, Aug 23, 2009 at 5:21 PM, Jeremy Shaw<jeremy at n-heptane.com> wrote:
> Also, you could define a forkM function like this:
> forkM :: M () -> M ThreadId
> forkM (M r) = M $ mapReaderT forkIO r
> which could be used like this:
> test = runM "foo" $ do
>         forkM $ loop callback
>         liftIO $ print "here"
> If we were to expand forkM in test, we would get something like:
> test' = runM "foo" $ do
>          env <- ask
>          liftIO $ forkIO (runM env $ loop callback)
>          liftIO $ print "here"
> So, this does not change the 'rule' of forkIO having to come before a
> runM. It just wraps it up nicely.

Somehow I missed this e-mail when I replied last time. Now this is
actually the solution to my problem. I didn't think of a second runM
with the same environment. Brilliant (OTOH it probably highlights the
fact that I am only a Monad novice).

Many thanks Jeremy. You saved my day!


More information about the Haskell-Cafe mailing list