| 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
- A new view of guards Simon L Peyton Jones
- Re: A new view of guards Lennart Augustsson
- Re: A new view of guards Manuel Chakravarty
- Re: A new view of guards Johannes Waldmann
- Re: A new view of guards Heribert Schuetz
- Re: A new view of guards Simon L Peyton Jones
- Re: A new view of guards Alex Ferguson
- Re: A new view of guards John Launchbury
- Re: A new view of guards Brian Boutel
- Re: A new view of guards Frank Christoph
- Re: A new view of guards Tony Davie
- Re: A new view of guards Andrew Moran
- Re: A new view of guards D. tweed
- Re: A new view of guards Greg Michaelson
- Re: A new view of guards Stefan Kahrs
- Re: A new view of guards Simon Marlow
