| We can avoid both the case expressions and the helper function by Simon
| Peyton Jones' guard syntax
|
| -- version 3
| simplify (Plus e e') | s <- simplify e ,
| s' <- simplify e',
| (Val 0) <- s
| = s'
| | s <- simplify e ,
| s' <- simplify e',
| (Val 0) <- s'
| = s
| | s <- simplify e ,
| s' <- simplify e'
| = (Plus s s')
| simplify e = e
I agree with the general thrust of your message (though I was unable to
think of a good syntax for it), but in this particular case there's no
problem. A where clause will do nicely:
simplify (Plus e e') | (Val 0) <- s = s'
| (Val 0) <- s' = s
| otherwise = Plus s s'
where
s = simplify e
s' = simplify e'
simplify e = e