[Haskell-beginners] Collapsing multiple case branches?
Alexander Dunlap
alexander.dunlap at gmail.com
Sat Jan 3 15:33:36 EST 2009
On Sat, Jan 3, 2009 at 12:04 PM, Thomas Davie <tom.davie at gmail.com> wrote:
> Hi Colin,
...snip...
> These are called "pattern guards" – you can put any boolean expression in
> them.
...snip...
Technically, those are just called "guards." "Pattern guards" are when
you also bind a pattern; it's a GHC extension. They look like this,
for example:
foo x
| Just y <- bar x = y + 1 -- this is the pattern guard. If bar x can
be matched with Just y, then y is bound and that guard path is taken.
Otherwise, evaluation falls through to the next guard option.
| otherwise = 0
Alex
More information about the Beginners
mailing list