Skip to content
This repository has been archived by the owner on Feb 7, 2019. It is now read-only.

Trait dispatch rules #5

Open
mauro3 opened this issue Jan 14, 2015 · 1 comment
Open

Trait dispatch rules #5

mauro3 opened this issue Jan 14, 2015 · 1 comment

Comments

@mauro3
Copy link
Owner

mauro3 commented Jan 14, 2015

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 #4 (comment) @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 #4 (comment) but let's continue this here.

@tonyhffong
Copy link
Collaborator

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants