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
Regards, Brian.
--
Logic empowers us and Love gives us purpose.
Yet still phantoms restless for eras long past,
congealed in the present in unthought forms,
strive mightily unseen to destroy us.
http://www.metamilk.com
_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe