[Haskell-cafe] Re: ANN: forkable-monad 0.1
David Anderson
dave at natulte.net
Wed Apr 21 19:38:58 EDT 2010
[-haskell]
On Wed, Apr 21, 2010 at 5:54 PM, Heinrich Apfelmus
<apfelmus at quantentunnel.de> wrote:
> 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.
>
> Nice work!
>
> It appears to me that this is subsumed by the recent MonadMorphIO
> proposal that Anders Kaseorg came up with, though?
>
> http://article.gmane.org/gmane.comp.lang.haskell.libraries/12902
>
>
> fork :: MonadMorphIO m => m () -> m ()
> fork m = morphIO $ \down -> forkIO (down m >> return ())
> >> down (return ())
Hmm, quite possibly. It is also quite similar to another
implementation of forkable monad stacks I came across after finishing
this first version of the library, and to what I had tentatively
called "unliftIO" with a slightly different type, in another
experiment in messing with forking monad stacks.
So, it seems that I am reinventing wheels that others have generalized
better :-). That's fine, it's the expected result of launching and
iterating, especially given my current command of Haskell. So I should
now focus on reducing the reinvention.
Most of the discussion that followed the message that you linked is
currently beyond my understanding of category theory. However, I
should probably go and talk to the maintainer of MonadCatchIO-* about
extracting something like MonadMorphIO into a package, and making both
their exception handling modules and this forking module reuse it.
Thanks for the pointer!
- Dave
> Regards,
> Heinrich Apfelmus
>
> --
> http://apfelmus.nfshost.com
>
> _______________________________________________
> 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