Jón Fairbairn jon.fairbairn at cl.cam.ac.uk
Tue Oct 10 05:18:52 EDT 2006

```"Brian Hulley" <brianh at metamilk.com> writes:

> Lennart Augustsson wrote:
> > I think your first try looks good.
> [snip]
> > ...
> > addPoly1 p1@(p1h@(Nom p1c p1d):p1t) p2@(p2h@(Nom p2c p2d):p2t)
> >    | p1d == p2d = Nom (p1c + p2c) p1d : addPoly1 p1t p2t
> >    | p1d < p2d = p1h : addPoly1 p1t p2
> >    | p1d > p2d = p2h : addPoly1 p1 p2t
> > ...
>
> The last comparison is redundant (this was in the original
> version too) because p1d > p2d is implied (certainly for
> this case where p1d, p2d::Int) by the fall through from not
> satisfying == and < so how about:
>
>     addPoly1 p1@(p1h@(Nom p1c p1d):p1t) p2@(p2h@(Nom p2c p2d):p2t)
>         | p1d == p2d = Nom (p1c + p2c) p1d : addPoly1 p1t p2t
>         | p1d < p2d = p1h : addPoly1 p1t p2
>         | otherwise = p2h : addPoly1 p1 p2t

Surely all but one of the comparisons is unnecessary? If you
use `compare` instead of (==) and friends, won't one do (I'm
assuming that the compiler can convert cases on LT, EQ and
GT into something sensible -- after all, wasn't that the
purpose of compare?)?

--
Jón Fairbairn                                 Jon.Fairbairn at cl.cam.ac.uk
http://www.chaos.org.uk/~jf/Stuff-I-dont-want.html  (updated 2006-09-13)

```