Pattern guards

Sebastian Sylvan sylvan at
Sat Sep 30 21:37:07 EDT 2006

On 10/1/06, Yitzchak Gale <gale at> wrote:
> Conor McBride wrote:
> > Claus Reinke wrote:
> >> ...the results of the translation are rather
> >> more awkward but -and this is the important
> >> point- pattern guards do not add new
> >> functionality.
> > Well, neither do Boolean guards nor even basic
> > pattern matching...  one simply should not need
> > to clutter a program with do, return, mplus and
> > fromJust (ugh!), spelling out the semantics of
> > pattern matching in minute detail. For at least
> > 36 years, we've been able to hide all that junk
> > behind a highly readable equational notation.
> > This is one monad we don't need to see.
> Some complex things are happening: selections and
> bindings are happening at the same time.  The
> monad spells it out clearly and concisely, without
> adding very much weight at all.

I would argue that most Haskell programmers would *never* write the
various snippets of code demonstrated in this thread in your way, on
the other hand pattern guards are convenient and easy enough to
understand (i.e. you don't have to know very much about monads), and
probably would get used. I certainly use them (and I *do* understand
monads enough to switch to your style of coding if I wanted to)!
Your way is nice and elegant if you happen to know enough to
understand it, pattern guards are nice and elegant to people who

> There has to be a really, really compelling reason
> to add new syntax to a language. Every bit of new
> syntax makes a language harder to learn, and less
> usable for the general user.

I disagree.
Adding syntactic sugar is cheap, as long as the core concepts are
small and elegant. I believe Haskell has taken this approach so far
(or do you want to get rid of e.g. list comprehensions as well? They
too are expressible quite elegantly with monads.), and I think pattern
guards are an excellent candidate in line with this.

It's a "natural" (in terms of "feel", fuzzy I know) generalisation of
guards, and simply won't affect anyone who think they are difficult in
any way. They are and intuitive and nice. They don't change the
behaviour of the "core" language, all they do is add a tiny bit of
syntactic sugar to make programmer's lives a little bit easier - and
they're not even adding anything completely new, just extending
existing features.

Sebastian Sylvan
UIN: 44640862

More information about the Haskell-prime mailing list