On 10/8/06, Udo Stenzel u.stenzel-at-web.de |haskell-cafe|
... wrote:
Yang wrote:
type Poly = [(Int,Int)]
addPoly1 :: Poly - Poly - Poly
addPoly1 p1@(p1h@(p1c,p1d):p1t) p2@(p2h@(p2c,p2d):p2t)
| p1d == p2d = (p1c + p2c, p1d) : addPoly1 p1t p2t
| p1d p2d = p1h : addPoly1 p1t p2
|
I think your first try looks good. The only thing to worry about
would be the + being too lazy. But that's easy to fix at the same
time as improving your code in another respect.
It's usually good to use real types instead of synonyms, so let's do
that.
data Nom = Nom Int Int
type
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
This email actually turned out much longer than I expected, but I hope
it sparks interesting (and hopefully, thorough!) discussion on points
that weren't touched on by previous threads on this topic. What
follows describes my journey thus far exploring what I see (as a
newcomer to Haskell) as a
On 10/8/06, Yang [EMAIL PROTECTED] wrote:
And do most (experienced) Haskell
users sacrifice cleanliness for speed, or speed for cleanliness?
Keep the internals of your code--that which will be looked at a
lot--fast and ugly, while the rest can be clean. If you have a
function that does
On 10/8/06, ihope [EMAIL PROTECTED] wrote:
Keep the internals of your code--that which will be looked at a
lot--fast and ugly, while the rest can be clean.
Sorry. Meant that which will be used a lot.
___
Haskell-Cafe mailing list
On 10/8/06, ihope [EMAIL PROTECTED] wrote:
On 10/8/06, Yang [EMAIL PROTECTED] wrote:
And do most (experienced) Haskell
users sacrifice cleanliness for speed, or speed for cleanliness?
Keep the internals of your code--that which will be looked at a
lot--fast and ugly, while the rest can be
On Sun, 2006-10-08 at 15:25 -0700, Jason Dagit wrote:
Another good idea when you have a pretty version which is easy to
verify for correctness and an ugly version that is harder to verify is
to use QuickCheck or SmallCheck and define a property that says both
versions are equal for all
duncan.coutts:
On Sun, 2006-10-08 at 15:25 -0700, Jason Dagit wrote:
Another good idea when you have a pretty version which is easy to
verify for correctness and an ugly version that is harder to verify is
to use QuickCheck or SmallCheck and define a property that says both
versions are
Yang wrote:
type Poly = [(Int,Int)]
addPoly1 :: Poly - Poly - Poly
addPoly1 p1@(p1h@(p1c,p1d):p1t) p2@(p2h@(p2c,p2d):p2t)
| p1d == p2d = (p1c + p2c, p1d) : addPoly1 p1t p2t
| p1d p2d = p1h : addPoly1 p1t p2
| p1d p2d = p2h : addPoly1 p1 p2t
addPoly1 p1 [] = p1
addPoly1 [] p2 =
10 matches
Mail list logo