[mercury-users] unification and polymorphism
bromage at cs.mu.OZ.AU
Wed Aug 5 18:12:49 AEST 1998
tom.howland at us.pwcglobal.com wrote:
> > I can understand the difference between (2) and (3): it is the cost of
> > polymorphism, right ? A bit higher than I expected I must say.
> I would have guessed polymorphism would be resolved at compile time.
What I think you meant is not _resolution_ of polymorphism, but
_specialisation_. That is, if you know what a certain polymorphic
type variable is bound to, create a specialised predicate with the
variable bound in the hope of efficiency gains.
The trouble here is that it's unclear if the gain that you get by
specialisation is outweighed by the loss in code bloat (and hence
increased code page faults), extra compilation time and so on. For
this reason, list unifications are specialised only on mode, not on
type, and even then only if the unification doesn't basically down to
a mode like "'='(in, in) is semidet".
Well, that's how it currently works. Thomas Conway is currently
working on a framework for solving this problem by feeding profile
information back into the compiler so that it can make some more
intelligent decisions on when to specialise.
More information about the users