[Haskell-beginners] type of pattern matching

Stephen Tetley stephen.tetley at gmail.com
Wed Jul 7 03:26:50 EDT 2010


Hi Michael

Untested - maybe you can use Record puns (section 7.3.15.of the GHC
manual). Though they might only work if you have used field names in
your data type.

{} swaps for _ _ _ _ _ _  so it would be:

> doSomething :: Maybe Result
> doSomething item = case item of
>  note@(Note {}) -> Just $ process note
>  _                     ->  Nothing


More information about the Beginners mailing list