| > For example, in this case we could write (rather less elegantly)
| >
| > g2 a | (x:xs) <- h a, (y:ys) <- h x = if y<0 then e1
| > else if y>0 then e2
| > else e3
| >
| > To avoid this difficulty with functions like g2...
|
| Why does the Haskell community have such an antipathy to if...then...else...?
| Tony said that choice of construct is a matter of personal style. Nonetheless,
| I think that this whole debate crystalises a consensus that guards are
| prefereable to conditional expressions.
Thas's easily explained. The reason I might not want to use if-then-else is
because there might be a subsequent equation I want to try if this one
fails. Like this:
g2 a | (x:xs) <- h a, (y:ys) <- h x, y<0 = e1
g2 a | (x:xs) <- h a, (y:ys) <- h x, y>0 = e2
g2 a | not (foo a) = e3
g2 a | otherwise = e4
Does that help? (Of course one can compile all pattern matching into
case and if-then-else; that's what the semantics in the report does. But
then your functions definitions tend to trail off to the right of the page
and can get hard to read.)
Simon