[Haskell-cafe] Language semantics
Jon Cast
jcast at ou.edu
Wed Jun 27 17:03:20 EDT 2007
On Wednesday 27 June 2007, Andrew Coppin wrote:
> I have a tricky little question...
>
> Suppose I write a function like this:
>
> foo pattern1
>
> | gard1 = ...
> | gard2 = ...
>
> foo pattern2
>
> | gard3 = ...
> | gard4 = ...
>
> According to one tutorial I read, if pattern1 matches, pattern2 will
> never be tried, even if both guard1 and guard2 fail.
>
> And according to another tutorial I read, if pattern1 matches but all
> guards fail, pattern2 *will* be tried.
>
> Can somebody comfirm which one is actually correct?
You could just try it, you know . . .
Anyway, the second tutorial is correct: if all guards on pattern1 fail,
pattern2 will be tried next. See Section 3.17.3 in the Haskell Report [1].
Btw., which was the first tutorial?
Sincerely,
Jonathan Cast
http://sourceforge.net/projects/fid-core
http://sourceforge.net/projects/fid-emacs
[1] http://haskell.org/onlinereport/exps.html#case-semantics
More information about the Haskell-Cafe
mailing list