[Haskell-cafe] Monad woes
Levi Greenspan
greenspan.levi at googlemail.com
Sun Aug 23 12:14:30 EDT 2009
Hi Jeremy,
On Sun, Aug 23, 2009 at 5:08 PM, Jeremy Shaw<jeremy at n-heptane.com> wrote:
> What you probably want is:
>
> test2' :: IO ()
> test2' = runM "foo" $ do
> loop callback
> liftIO $ print "here"
This equals my test1 version which is fine without forkIO.
> return $ loop callback :: (Monad m) => IO (M ())
>
> It is an IO operation which returns a value of type, M (). But,
> nothing is done with that value, it is just thrown away.
I see. This is what I feared.
> If you want to add a forkIO, the forkIO must go before the runM:
OK. I tried all kinds of combinations, but not forkIO in front of
'runM' . The reason being that I only use forkIO because 'loop' never
returns so in order to proceed I would have to put it into the
background. Basically I want two threads running inside the same M
monad.
> hope this helps.
Many thanks Jeremy. Your explanations are indeed very helpful. But
they also strengthen my gut feeling that running two threads in the
same M monad is hard (if not impossible) to do.
Cheers,
Levi
More information about the Haskell-Cafe
mailing list