| 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?

Probably not.  Remember that sum is *itself* overloaded, so if resultant calls 
sum there is not much it can do except pass on the appropriate dictionary to 
sum.

Better would be to inline (and specialise) sum at this call site.  But at the 
moment GHC doesn't specialise functions defined in *other* modules.  That's 
another thing that could be improved (at the cost of risking constructing 
multiple copies of the same specialisation of 'sum'.

Simon
_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to