[Haskell-beginners] case statement and guarded equations

Rein Henrichs rein.henrichs at gmail.com
Fri Jul 7 22:38:06 UTC 2017


Quoting the report[1], "A boolean guard, g, is semantically equivalent to
the pattern guard True <- g," which means the answer is "Yes". A boolean
guard is equivalent to a pattern match. A predicate involving ==, however,
introduces an Eq constraint that would not be required by pattern matching.
For a properly equivalent guard, you need to write your predicates using
pattern matching

isEven Even = True
isEven _ = False

to avoid the spurious Eq constraint.

[1]
https://www.haskell.org/onlinereport/haskell2010/haskellch3.html#x8-460003.13
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/beginners/attachments/20170707/b1fc864f/attachment.html>


More information about the Beginners mailing list