
23 Aug
2010
23 Aug
'10
2:56 p.m.
On 08/23/10 02:33, John Smith wrote:
Why doesn't Haskell allow something like this?
fac 0 = 0 1 = 1 x = x * fac (x-1)
This would be clearer than repeating the function name each time, and follow the same pattern as guards and case.
Layout is detected and parsed when and only when it is preceded by 'where', 'let', 'do', or 'of'. So Haskell would have to have some such keyword to indicate "let the layout begin!" -- which could make it a bit uglier -- but no I don't know why. Sometimes where there are tons of cases I define the function using 'case' instead -- I probably wouldn't for your above example, but to show how it'd be written, fac x = case x of 0 -> 0 1 -> 1 _ -> x * fac (x-1)