[Haskell-cafe] Re: (Chaos) [An interesting toy]

Andrew Coppin andrewcoppin at btinternet.com
Mon May 7 05:43:50 EDT 2007


Simon Peyton-Jones wrote:
> | The source code has explicit monomorphic types all over it; I would
> | expect GHC to be able to optimise out any method calls. (OTOH, I'm not a
> | GHC expert... Simon? Don?)
>
> Full monomorphisation is a whole-program optimisation and GHC isn't (yet) a whole-program compiler.  Overloaded functions are indeed specialised for the types at which they are called *in the module they are defined*.
>
> Simon
>   
What I'm trying to say is, I would have expected, say,

  resultant :: [Vector2] -> Vector2
  resultant = sum

to run faster than

  resultant = sum

In the latter case, we have resultant :: (Num n) => [n] -> n. I'm no 
expert, but I would expect that this requires a method lookup on each 
call, whereas with the more restrictive type I would expect the compiler 
to be able to just link directly to the correct method implementation. 
Am I mistaken?



More information about the Haskell-Cafe mailing list