[Haskell-cafe] Re: Guards with do notation?
mail at joachim-breitner.de
Tue Oct 24 07:20:40 EDT 2006
Am Dienstag, den 24.10.2006, 12:48 +0200 schrieb Benjamin Franksen:
> > Am Dienstag, den 24.10.2006, 00:44 +0300 schrieb Misha Aizatulin:
> >> hello all,
> >> why is it not possible to use guards in do-expressions like
> >> do
> >> (a, b) | a == b <- getPair
> >> return "a and b are equal"
> > Probably because it is not well-defined for all Monad what a failure is,
> > i.e. what to do in the other case. or something. Just my guess.
> No, fail is indeed a method of class Monad, and it is there exactly for this
> reason, i.e. because pattern matching may fail (even without guards, think
> Just a <- ...
> ) The restriction is there because guards are not allowed in lambda
> expressions, for which do-notation is merely syntactic sugar. (Some people
> have argued for lifting this restriction in Haskell', see
Then why is the “guard” function, which can be used in a way to
implement what Misha wants, only available in MonadPlus, and not in
e-Mail: mail at joachim-breitner.de
More information about the Haskell-Cafe