mauro3 / Traits.jl

Exploration of traits in Julia
Other
39 stars 6 forks source link

Trait dispatch rules #5

Open mauro3 opened 9 years ago

mauro3 commented 9 years ago

It is not clear yet how trait dispatch should work. The current rules (which are mostly implemented) are:

a) find all matching traits
b) discriminate using subtraits, i.e. a subtrait will win over its supertrait
c) score all traits according to:
   1 point for all single parameter traits,
   2 points for all two parameter traits,
    etc.
    Now pick the highest scoring method.
d) if still ambiguous throw an error

Over in PR https://github.com/mauro3/Traits.jl/pull/4#issuecomment-69631916 @tonyhffong suggested some new rules:

a1) The base score is 1.0 + the maximum score of supertrait. 
    This is the dominant driver, assuming that each layer of trait inheritance adds a 
    significant notion of "specificity" to the match.
b2) each constraint in the trait definition, including the number of supertraits 
    (since it is just a constraint of istrait(SuperTr{X}) in disguise) would add 
    0.1 to the score.
c2) each number of parameters above 1 would add 0.01 to the score

We discussed the rules following https://github.com/mauro3/Traits.jl/pull/4#issuecomment-69631916 but let's continue this here.

tonyhffong commented 9 years ago

I just realized that my a1) rule by itself basically provides one (non-unique) topological sort sequence, for what it's worth.