[Haskell-cafe] Is there anything manifestly stupid about this
code?
Luke Palmer
lrpalmer at gmail.com
Mon Jul 7 08:37:52 EDT 2008
On Mon, Jul 7, 2008 at 2:21 PM, Michael Feathers
<mfeathers at mindspring.com> wrote:
> Thanks. Here's a newb question: what does strictness really get me in this
> code?
A bit of speed and memory improvements, I suspect. The type
(Double,Double) has three boxes, one for the tuple and one for each
double. The type Complex, which is defined as
data Complex a = !a :+ !a
has one box (after -funbox-strict-fields has done its work), the one
for the type as a whole. So it will end up using less memory, and
there will be fewer jumps to evaluate one (a jump is made for each
box).
> BTW, I only noticed the Complex type late. I looked at it and noticed that
> all I'd be using is the constructor and add. Didn't seem worth the change.
You would also be using the multiply and magnitude functions! And you
would gain code readability, since you could define:
mandel c z = z^2 + c
trajectory c = iterate (mandel c) 0
Which is basically the mathematical definition right there in front of
you, instead of splayed out all over the place.
Luke
More information about the Haskell-Cafe
mailing list