[Haskell-beginners] The cost of generality, or how expensive is realToFrac?

Daniel Fischer daniel.is.fischer at web.de
Mon Sep 20 10:53:25 EDT 2010


On Monday 20 September 2010 05:09:16 you wrote:
> I'm building with the latest Haskell Platform.  GHC 6.12.3 and OpenGL
> 2.2.1.1

:sigh:

So we can forget about rewrite rules, newtypes, unsafeCoerce and all that 
Jazz.

In OpenGL-2.2.1.1, GLclampf (and GLfloat &c.) were not newtypes, they were 
type synonyms,

type GLclampf = Float

and so on.
So it's clear that GHC rewrites realToFrac to double2Float# in the 
benchmark, since it's converting to Float (that also explains the absence 
of casts in your core).

Then, if floatToFloat is faster than realToFrac in your programme (compiled 
with optimisations), that probably means GHC doesn't spot an opportunity to 
replace realToFrac with double2Float# because the types are still 
polymorphic. Perhaps some type annotations would help.


More information about the Beginners mailing list