[Haskell-cafe] the case of the 100-fold program speedup

Seth Gordon sethg at ropine.com
Wed Nov 15 09:49:20 EST 2006

Henning Thielemann wrote:
> On Tue, 14 Nov 2006, Seth Gordon wrote:
>>It took me a week to figure out the right algorithm for combining these
>>two procedures and write some almost-working code that implemented it.
>>It took a co-worker of mine another few days to find the bugs that had
>>eluded me.
> Were these bugs of the kind that would have been found by a static type
> checker, say the one of Haskell?

The most significant bug that my co-worker caught was in the math, not
the implementation--when translating the centroid formula from big-sigma
notation to a recurrence, I accidentally wrote (x_i x_{i+1}) when I
should have written (x_i + x_{i+1}).  My stupidity surpasses the
stupidity-catching power of the type checker.

There were less significant bugs that probably would have been caught by
static type checking, but in this case I think the unit tests caught
them just as quickly.

The "producer" part of the clip-and-centroid algorithm generates 0, 1,
or 2 vertices for every vertex of the original polygon, which are then
fed into the "consumer" part to compute the centroid.  It did cross my
mind as I was writing the Python code that this sort of thing could be
handled much more concisely with the List monad, but doing the whole
thing in Haskell would have required (a) writing Haskell glue code to
either interface with the OGR library or parse WKT strings, and (b)
convincing my co-workers that Haskell was *so* incredibly useful that it
was worth adding another language as a build-time dependency.

(I'm laying the groundwork for (b) in my Copious Free Time....)

> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe

More information about the Haskell-Cafe mailing list