13 Nov 11:05
Re: Pattern Matching
Andrew Coppin <andrewcoppin <at> btinternet.com>
2009-11-13 10:05:15 GMT
2009-11-13 10:05:15 GMT
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...)
>
> 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...)
RSS Feed