Skip to content

polymorphic overload optimization? #39

@dylex

Description

@dylex

Consider the overload length :: [a] -> Int. This function can be inferred identically (returning Int) for any use that matches this overload.

The overload head :: [a] -> a also could be inferred identically, if we allow type variables in the return.

However, the overload sum :: [a] -> _ cannot be, becuse which overload(s) (of +) it uses depends on the type a.

This suggests an optimization for overload resolution. First we need something between TypeVal and TypePat that is TypeVal + variable.

During function inference, we could simply treat argument types in the local environment as lazy somehow, such that whenever we actually use a TypeVal for overload resolution, it gets fully resolved, but any types we end up not needing for resolution we know can stay as type variables.

Then, for overload resolution, we just need some special kind of map in the ptrie that knows that anything can be a type variable when looking up concrete TypeVals.

I'm not sure whether this complicates fixpoint resolution. It might not, but if it does it could always be done as a second pass to "generalize" the overload table.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions