-
Notifications
You must be signed in to change notification settings - Fork 145
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(check): Don't instantiate variables during unification inside ali…
…ases The unification algorithm accidentally were to eager to instantiate generic variables with fresh type variables which allowed programs to pass typechecking even though they differed in the placement of variables (see tests). This fixes that by *ONLY* instantiating fresh typevariables during subsumption (deduced from Purescript's implementation), otherwise we only skolemize the variables (which ensures that different variables do not unify with each other). This would be enough to fix this, except the current way typechecking proceeds throw a wrench into the mix. Consider the following example. ```f# type Functor f = { map : forall a b . (a -> b) -> f a -> f b, } let functor : Functor List = let map = ... { map } ``` Since we want to preserve the alias during typechecking as long as possible (both as an optimization as well as to present better error messages), we do not immediately skolemize the inner `forall` binding. Instead we only do this once unification forces us to look inside `Functor List`. This is a problem if we end up skolemizing the same type *twice* as the skolem constants from each time will not match. ``` { map : (a@0 -> b@1) -> List a@0 -> List b@1 } <=> { map : (a@2 -> b@3) -> List a@2 -> List b@3 } a@0 != a@2 ``` I remedied this by moving the `merge_signature/subsumption` call that was done on each `let` binding into the typechecking procedure itself which has the effect of making this subsumption only happen once for each part of the type.
- Loading branch information
Showing
6 changed files
with
220 additions
and
106 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.