[Haskell-cafe] Understanding GHC allocations

Roman Beslik beroal at ukr.net
Thu Jun 17 12:12:24 EDT 2010

On 17.06.10 12:40, Roman Cheplyaka wrote:
> > From reading core I got the impression that everything is strict&
> unboxed. Perhaps this is related to creating some closures? How to get
> rid of those allocations?
Yes, "distance" creates a closure of type @Double -> Double# -> Double@ 
which is obviously not necessary. I do not know why.

> 2. Again from reading the core I learned that although 'l' and other
> constants are inlined, their type is boxed Double. This makes sense
> since CAFs are evaluated on demand, but obviously in this particular
> case it does not make sense, so can I somehow make them unboxed
Hmm, I learned from "-ddump-core" that "distance" function uses constant 

There is another way to optimize — make GHC use floating point "abs" 
processor instruction. Now it uses
abs x | x >= 0.0 = x
| otherwise = negateDouble x

Best regards,
   Roman Beslik.

More information about the Haskell-Cafe mailing list