[Haskell-cafe] Re: Using the ContT monads for early exits of IO ?

Ertugrul Soeylemez es at ertes.de
Wed Jun 16 22:07:41 EDT 2010

Hello Günther,

I use ContT monads for early exit often, because that's one of the
things they encode naturally.  But I don't do this with callCC.  I
prefer monadLib over mtl/transformers, which has a specific function for

  abort :: (AbortM m i) => i -> m a

where AbortM is a class for monads, whose computations are abortable.
All ContT monads are instances.  This is also a nice way to break out of

Using an error monad (like Maybe) may be more natural of course.


Günther Schmidt <gue.schmidt at web.de> wrote:

> Hi everyone,
> I'm about to write a rather lengthy piece of IO code. Depending on the 
> results of some of the IO actions I'd like the computation to stop right 
> there and then.
> Now I know in general how to write this but I'm wondering if this is one 
> of those occasions where I should make use of the Cont monad to make an 
> early exit.
> Günther

nightmare = unsafePerformIO (getWrongWife >>= sex)

More information about the Haskell-Cafe mailing list