[Haskell-beginners] type of pattern matching

David Virebayre dav.vire+haskell at gmail.com
Wed Jul 7 03:27:24 EDT 2010


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 _ _ _ _ _"


More information about the Beginners mailing list