[Haskell-beginners] Offside rule for function arguments?
daniel.is.fischer at web.de
Mon Aug 23 15:14:43 EDT 2010
On Monday 23 August 2010 21:02:50, Brandon S Allbery KF8NH wrote:
> On 8/23/10 14:56 , Isaac Dupree wrote:
> > 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
> I think the next question is "so how do guards work?"
Not by layout:
function :: Int -> Int -> Int -> Bool
function x y z | even x = y > z | odd y = even (z-x) | otherwise = even z
Guards are introduced by the token `|', they need not be aligned, you can
have multiple on the same line.
More information about the Beginners