[Haskell-beginners] type of pattern matching
Michael Mossey
mpm at alumni.caltech.edu
Wed Jul 7 03:19:43 EDT 2010
What if I want to check if a variable uses a particular constructor, but I
don't want to unpack it. For example:
data Item = Note Int Float Rational [Int] [Float]
| Dynamic Int
And I want to write
doSomething :: Maybe Result
doSomething item = case item of
note@(Note _ _ _ _ _) -> Just $ process note
_ -> Nothing
But I don't like writing "Note _ _ _ _ _"
Thanks,
Mike
More information about the Beginners
mailing list