[Haskell-beginners] Offside rule for function arguments?
ml at isaac.cedarswampstudios.org
Mon Aug 23 14:56:18 EDT 2010
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)
More information about the Beginners