[Haskell-cafe] Pattern Matching

Daniel Fischer daniel.is.fischer at web.de
Fri Nov 13 07:02:53 EST 2009


Am Freitag 13 November 2009 11:05:15 schrieb Andrew Coppin:
> Colin Paul Adams wrote:
> > If I had a dollar for every time I've written something like
> >
> >     Andrew>  case msg of eVENT_QUIT -> ...  eVENT_POST -> ...
> >     Andrew> eVENT_RESIZE -> ...
> >
> >     Andrew> and spent an hour trying to figure out why the messages
> >     Andrew> aren't being processed right... ;-)
> >
> > So why aren't they?
>
> Because what I *should* have written is
>
>   case msg of
>     _ | msg == eVENT_QUIT -> ...
>
>        | msg == eVENT_POST -> ...
>        | msg == eVENT_RESIZE -> ...
>
> which is something quite different.
>
> (And, entertainingly, because the incorrect version is perfectly valid
> source code, no compiler errors or warnings...)

It yells "overlapping patterns" -- you do pass -Wall, don't you?





More information about the Haskell-Cafe mailing list