[Haskell-cafe] Future of MonadCatchIO

Michael Snoyman michael at snoyman.com
Sun Mar 3 17:24:27 CET 2013


On Sun, Mar 3, 2013 at 6:07 PM, Ertugrul Söylemez <es at ertes.de> wrote:

> Arie Peterson <ariep at xs4all.nl> wrote:
>
> > Would anyone have a problem with a deprecation of
> > MonadCatchIO-transformers, and a failure to update it to work with a
> > base without 'block' and 'unblock'?
>
> Yes.  This is a simplified variant of a monad I use:
>
>     newtype Continue f m a = Continue (m (Maybe a, f (Continue f a)))
>
> It's related to Cofree and has a valid and very straightforward
> MonadCatchIO instance.  However, it's probably impossible to write a
> valid MonadTransControl/MonadBaseControl instance for it.
>
>
Perhaps there's a good reason why it's impossible to make such an instance.
Are you sure that your MonadCatchIO instance is well founded? What happens
if you use finally? Are you guaranteed that your cleanup function is called
once, and precisely once?

These are the problems I ran into with MonadCatchIO three years ago, almost
precisely. The main monad for Yesod was built around ContT, and I ended up
with double-free bugs. It's true that I had to move away from ContT in
order to get the desired semantics, but that has nothing to do with
MonadCatchIO vs monad-control. The former just made it seem like I had
working code when in fact I had a lurking bug.


> So I kindly ask you not to deprecate MonadCatchIO.  The reason I'm
> hesitant about moving to monad-control is that it's hard to understand
> and also very difficult to define for CPS monads.  It is commonly
> believed to be impossible.
>
> Also I've seen at least one article about the incorrectness of
> monad-control.  That's one further reason I like to avoid it.
>
>
I've seen the criticisms of monad-control (or at least I believe I have).
What I've seen has been dubious at best. I'll fully agree that the
implementation is hard to follow, but it's designed for efficiency. The
underlying concept is simple: capture the current state and pipe it through
the underlying monad. If you needed to lift a control operation for the
ReaderT or StateT monads, you would likely end up with an almost exact
replica of what monad-control does for you.

Michael
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20130303/7720c2a5/attachment.htm>


More information about the Haskell-Cafe mailing list