Pattern guards

Yitzchak Gale gale at
Thu Sep 28 19:59:49 EDT 2006

Iavor Diatchki wrote:
> ...we can encode them using the Maybe monad, but the same is
> true for nested patterns, and I don't think that they should be
> removed from Haskell.

The fact that pattern guards can be "encoded as monads"
is not the problem. The problem is that they are a
confusing syntax that does not add anything new.

> I think that the benefit of adding pattern
> guards is... it provides a
> concise notation

Not significantly more concise than existing

> that is easy to explain and understand

As an educator, I disagree. What does
"pat <-  exp" mean? It has a completely
new meaning here, just similar enough to
existing semantics to be very confusing.

> without having to first learn about monads

Why is everyone so afraid of monads?
They are one of the most beatiful and useful
features of Haskell, and one uses them all the
time in even the simplest programs.

It is not hard to give a beginner a basic,
practical, working knowledge of the common
monads. Deeper understanding can come later.
I think this should be added right near the beginning
of every Haskell tutorial.

> ...pattern guards are quite easy to implement...

Yes, pattern guards are low-hanging fruit for compiler
implementors. They seem so obvious and easy
to understand for those of us who have been in
the habit of using them. But I think it is time to step
back and take a more objective look at them.


More information about the Haskell-prime mailing list