[Haskell-cafe] ANN: forkable-monad 0.1

David Anderson dave at natulte.net
Wed Apr 21 19:22:07 EDT 2010

On Wed, Apr 21, 2010 at 4:39 PM, Neil Brown <nccb2 at kent.ac.uk> wrote:
> Hi,
> This is quite a neat generalisation of forkIO, and something I've wanted in
> the past.
> My comment would be about the MonadIO m requirement for ForkableMonad.  I
> understand that conceptually it's a nice thing to have.  But practically, I
> don't think it's necessary, and could be a little restrictive -- I could
> imagine potentially having a newtype-wrapped monad that doesn't have a
> MonadIO instance, but does have a ForkableMonad instance.  I tried removing
> the MonadIO constraint, and it works as long as you add a Monad constraint
> either to the class or to the ReaderT and StateT instances.  That depends if
> you can imagine an instance of ForkableMonad that wasn't a Monad (an
> applicative perhaps)... probably not, especially given the name.
> In short: I recommend changing MonadIO m to Monad m on the class.

Hmm, I see. Originally I defined the MonadIO constraint because it
seemed the best way to state that the monad stack should have IO at
its core, to allow for calling the classic forkIO at some point. That
said, the argument for a newtyped stack that doesn't implement MonadIO
does make some sense.

Change submitted and pushed at
http://code.google.com/p/forkable-monad/source/detail?r=89 . Thanks!

> I came up with this instance for ContT:
> instance (ForkableMonad m) => ForkableMonad (ContT r m) where
>  forkIO act = lift $ forkIO (runContT act (const $ return undefined))
> I don't know if that's useful and/or correct, though.

Hmm. Good question. I haven't quite wrapped my head around ContT yet,
but I'll make a note to meditate over your implementation. If it makes
sense in the context of forking threads, I'll add it to the

Thanks again,
- Dave

> David Anderson wrote:
>> Dear Haskellers,
>> I'm happy, and only slightly intimidated, to announce the initial
>> release of forkable-monad.
>> The short version is that forkable-monad exports a replacement forkIO
>> that lets you do this:
>> type MyMonad = ReaderT Config (StateT Ctx IO)
>> startThread :: MyMonad ThreadId
>> startThread = forkIO threadMain
>> threadMain :: MyMonad ()
>> threadMain = forever $ liftIO $ putStrLn "Painless monad stack forking!"
>> Note the lack of monad stack deconstruction and reconstruction to
>> transport it over to the new thread. You'll find the details in the
>> Haddock documentation for the module.
>> forkable-monad is available:
>> * On hackage: http://hackage.haskell.org/package/forkable-monad
>> * Via cabal: cabal install forkable-monad
>> * Source and issue tracker: http://code.google.com/p/forkable-monad/
>> Feedback is of course welcome. As this is my first published Haskell
>> code and Hackage upload, I expect there will be quite a bit!
>> - Dave
>> _______________________________________________
>> Haskell-Cafe mailing list
>> Haskell-Cafe at haskell.org
>> http://www.haskell.org/mailman/listinfo/haskell-cafe

More information about the Haskell-Cafe mailing list