[Haskell-cafe] Guards with do notation?

David House dmhouse at gmail.com
Tue Oct 24 06:46:37 EDT 2006

On 24/10/06, Joachim Breitner <mail at joachim-breitner.de> wrote:
> 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.

Exactly the same thing that guards do elsewhere? Count the falsity of
the guard as a pattern match failure. It's precisely the same as
doing, e.g.:

do Just (a, b) <- Nothing
   return "a and b were Just"

Pattern-match failure in a do-block invokes fail in that monad.

-David House, dmhouse at gmail.com

More information about the Haskell-Cafe mailing list