|
![](/i/fill.gif) |
On 17/10/2015 02:09 PM, Orchid Win7 v1 wrote:
> I've been a Haskell programmer for [at least] 10 years, and I've never
> seen *anybody* do this!
In other news...
It turns out guards are weirder than I thought! Most humans use them
like this:
fibonacci n | n == 0 = 1
| n == 1 = 1
| otherwise = fibonacci (n-1) + fibonacci (n-2)
Or maybe
fibonacci n
| n == 0 = 1
| n == 1 = 1
| otherwise = fibonacci (n-1) + fibonacci (n-2)
But it turns out, it's 100% legal to do this:
fibonacci n | n == 0 = 1 | n == 1 = 1 | otherwise = ...
How bizarre! I had no idea you could do this... I had assumed the layout
rule applies. But, apparently, it does not. So long as all the guards
end up in the same block, it literally doesn't matter. Who knew?
(I suppose most of this basically boils down to "most people don't use
guards very much anyway"...)
Post a reply to this message
|
![](/i/fill.gif) |