[Haskell-cafe] ANN: forkable-monad 0.1

Neil Brown nccb2 at kent.ac.uk
Wed Apr 21 10:39:17 EDT 2010


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.

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.



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