Improve unification ranking by taking type frequency into account
Problem to solve
For example, at the moment it is not possible to add a ranking constraint
, [{"unify":"String -> Int"}, ["LT",["Function","StdOverloaded","toInt"], ["Function","Data.GenHash","murmurHash"]]]
because it clashes with things like
, [{"unify":"String -> Expr"},["LT",["Function","Text.GenParse","preParseString"],["Function","StdMisc","abort"]]]
, [{"unify":"String -> Expr"},["LT",["Function","Text.GenParse","preParseString"],["Function","Text.GenParse","ExprError"]]]
, [{"unify":"String -> Expr"},["LT",["Function","Text.GenParse","ExprError"], ["Function","StdMisc","abort"]]]
, [{"unify":"String -> TaskException"},["LT",["Function","iTasks.WF.Definition","exception"],["Function","StdMisc","abort"]]]
The latter constraints are good because Expr
and TaskException
are very specific types: if the user asks for them, they are very important. String
in the first (newly suggested) constraint is much less important. It is relatively more important that toInt
comes from StdEnv and has lots of uses, while murmurHash
does not.
Proposal
Add an index with the number of times types are used (perhaps the logarithm of this number). When using a unifier to rank, unifications with frequent types should create less distance than unifications with infrequent types.
Documentation
None.
Edited by Camil Staps