[Haskell-beginners] type of pattern matching
Michael Mossey
mpm at alumni.caltech.edu
Wed Jul 7 04:15:42 EDT 2010
David Virebayre wrote:
> On Wed, Jul 7, 2010 at 9:19 AM, Michael Mossey <mpm at alumni.caltech.edu> wrote:
>> doSomething :: Maybe Result
>> doSomething item = case item of
>> note@(Note _ _ _ _ _) -> Just $ process note
>> _ -> Nothing
>>
>> But I don't like writing "Note _ _ _ _ _"
>>
>
>
> isNote (Note _ _ _ _ _) = True
> isNote _ = False
>
> doSomething :: Maybe Result
> doSomething item | isNote item = Just $ process note
> | otherwise = Nothing
>
> But I don't like writing "Note _ _ _ _ _"
I think this is pretty good because I can use isNote with a filter in
another function.
Thanks,
Mike
More information about the Beginners
mailing list