[Haskell-cafe] A simple beginner question
Luke Palmer
lrpalmer at gmail.com
Wed Jun 4 00:28:15 EDT 2008
On Tue, Jun 3, 2008 at 6:48 PM, Ronald Guida <oddron at gmail.com> wrote:
> filter (\x -> case x of A -> True; otherwise -> False) sampleTypes
> ==> [A]
>
> filter (\x -> case x of B _ -> True; otherwise -> False) sampleTypes
> ==> [B 5]
There's a neat little mini-trick for these types of pattern matches:
filter (\x -> case x of B {} -> True; otherwise -> False) sampleTypes
Does the same thing, but works no matter how many arguments the
constructor B takes.
Luke
More information about the Haskell-Cafe
mailing list