ML like pattern matching
Ganesh Sittampalam
ganesh@earth.li
Fri, 22 Aug 2003 16:19:50 +0100
On Fri, 22 Aug 2003 15:49:15 +0300, "Cagdas Ozgenc" <co19@cornell.edu>
wrote:
>How do I emulate the "when" clause in ML for pattern matching? In other
>words when a pattern is matched (from a list of patterns of a function) and
>to enforce additional predicates I use guards, but if the guard condition is
>not satisfied I want Haskell to get back to trying the remaining patterns.
I may be confused about what you're asking for, but Haskell does this by
default:
foo (Left x) | x>3 = "bar"
foo _ = "splat"
Main> foo (Left 5)
"bar"
Main> foo (Left 1)
"splat"
Ganesh