[Haskell] Syntax Q: How do you share RHS's in case expressions!?
Scott Turner
p.turner at computer.org
Fri Oct 22 12:26:17 EDT 2004
On 2004 October 22 Friday 12:15, Ben Rudiak-Gould wrote:
> Ryan Newton wrote:
> > [...]
> > case 3 of 3 -> 99; 4 -> 99
>
> You can do this:
>
> let rhs = (some complicated expression) in
> case 3 of
> 3 -> rhs
> 4 -> rhs
You can also do
case 3 of x | x `elem` [3,4] -> 99
though strictly speaking that's not using pattern matching to get the job
done. Haskell syntax doesn't provide a way to associate multiple patterns
with one right hand side.
More information about the Haskell
mailing list