Cost of Overloading vs. HOFs

Adrian Hey ahey at iee.org
Fri May 4 14:28:41 EDT 2007


Hello,

The GHC users guide says overloading "is death to performance if
left to linger in an inner loop" and one thing I noticed while
playing about with the AVL lib was that using a HOF and passing
the (overloaded) compare function as an explicit argument at the
start seemed to give noticable a performance boost (compared with
dictionary passing presumably).

I'm not sure why that should be, but has anyone else noticed this?

If so, maybe this advice should be added to the user guide, especially
if your function repeatedly uses just one method from a class?

(or maybe not if it's nonsense :-)

I guess having done this there would be little to gain by using the
SPECIALIZE pragma though (unless ghc also specialises HOFs).

Regards
--
Adrian Hey


More information about the Glasgow-haskell-users mailing list