[Haskell-cafe] Haskell guards
Stefan O'Rear
stefanor at cox.net
Thu Sep 20 10:14:17 EDT 2007
On Thu, Sep 20, 2007 at 05:20:46PM +0400, Victor Nazarov wrote:
> I still can't remember how guards are treated in Haskell. Here is the
> code snippet in question:
>
> foo a | a == 1 = 6
> foo a | a == 2 = 7
> foo a = 8
>
> Would Haskell fall through to the third alternative if a is not equal
> to 1 or 2. I know that this can be rewritten more sanely, but I just
> consider guard behavior. What would be the value of (foo 3)?
8.
It falls through if no guards in a rhs match.
Stefan
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
Url : http://www.haskell.org/pipermail/haskell-cafe/attachments/20070920/8e1cbbc2/attachment-0001.bin
More information about the Haskell-Cafe
mailing list