[Haskell-cafe] Re: what is inverse of mzero and return?
k.schupke at imperial.ac.uk
Tue Jan 25 08:20:36 EST 2005
Jules Bean wrote:
> Well, mzero isn't a return value in the IO monad, it's an exception.
> But yes, I agree with you that the (plausible) laws I have seen for
> MonadPlus seem to say that mzero should ignore the actions. But this
> in practice is not how IO behaves.
I can see three possible solutions:
1) IO is not an instance of MonadPlus (but may still be an instance
2) Side effects are ignored (or state is ignored) and IO may be an
instance of MonadPlus
3) bind (>>=) is redefined for IO. As the IO Monad is a function
which resturns a computation,
bindIO can be changed such that (a >> mzero === mzero). In other
words if the RHS is mzero, the
LHS is not included in the final result (and its actions would not
get executed), however this
must be inconsistent if we consider:
f = getChar >>= (\a -> if a == "F" then mzero else return a)
In this case if the LHS returns "F" the LHS should not have been
run... this contradicts itself, so
this is a non option I guess.
Acutally looking at GHC CVS libraries, there is not a definition for
MonadPlus on the state or IO
More information about the Haskell-Cafe