[Haskell-cafe] Using the ContT monads for early exits of IO ?
Christopher Done
chrisdone at googlemail.com
Fri Jun 11 08:06:05 EDT 2010
On 11 June 2010 10:12, Roman Cheplyaka <roma at ro-che.info> wrote:
> * Günther Schmidt <gue.schmidt at web.de> [2010-06-11 01:22:27+0200]
>> there is nothing wrong with ifs as such except the won't actually
>> exit a long piece of code, the computation will continue, just in a
>> useless way.
>
> Can you clarify?
I think Günther assumed that I was suggesting:
do if x
then return ()
else bar
continueComputation
The problem is that if 'x' is true, continueComputation should
never happen. So you can solve it like this, which is what I was
actually suggesting:
do if x
then return ()
else do bar; continueComputation
But then you have this problem, which Günther addressed:
2010/6/11 Günther Schmidt <gue.schmidt at web.de>:
> Primarily for every "if" I need two forks, so at every "if" the
> branches double.
Which can be a big problem if you have a sequence of heterogenous
actions that must be executed in order and are dependant and
nested. Continutations solve this, as do ErrorT and MaybeT which
are both restricted subsets for returning values. I'd use MaybeT
if a value needed to be returned, or nothing.
More information about the Haskell-Cafe
mailing list