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

Christopher Done chrisdone at googlemail.com
Thu Jun 10 18:57:22 EDT 2010


2010/6/10 Günther Schmidt <gue.schmidt at web.de>:
> 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.

What's wrong with a mere if/else condition?

foo = do
  bar
  x <- mu
  case x of
    Bar -> return ()
    Mu -> do y <- zot
             case y of
               Zot -> return ()
               Foo -> gud

foo = do
 bar
 x <- mu
 y <- bar
 when (pred x y) $ do
    zot x

Continuations are risky for causing confusion of readers (and the
author herself), do you definitely need this?


More information about the Haskell-Cafe mailing list