[Haskell-cafe] Pattern Matching
Andrew Coppin
andrewcoppin at btinternet.com
Fri Nov 13 05:05:15 EST 2009
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...)
More information about the Haskell-Cafe
mailing list