Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error in substitution algorithm #116

Open
brianberns opened this issue Nov 26, 2022 · 1 comment
Open

Error in substitution algorithm #116

brianberns opened this issue Nov 26, 2022 · 1 comment

Comments

@brianberns
Copy link

brianberns commented Nov 26, 2022

The Substitutable instance for Type is currently defined as follows:

instance Substitutable Type where
  apply _ (TCon a)       = TCon a
  apply s t@(TVar a)     = Map.findWithDefault t a s
  apply s (t1 `TArr` t2) = apply s t1 `TArr` apply s t2

I believe the TVar case is incomplete. Consider the following substitution:

x <- y
y <- Int

If we apply this substitution to type variable x, we obtain y, when we should obtain Int. I think this case should instead recursively apply the substitution to the type found in the map.

@brianberns
Copy link
Author

brianberns commented Nov 28, 2022

For reference, here's an example where this problem occurs:

  • Unify types x -> x and y -> Int.
  • Input types x and y are unified, producing substitution x <- y.
  • This substitution is applied to output types x and Int, producing y and Int.
  • Output types y and Int are unified, producing substitution y <- Int.
  • The two substitutions are composed, producing x <- y, y <- Int.

One might argue instead that the composed substitution should be x <- Int, but this is not the current behavior of the algorithm.

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

No branches or pull requests

1 participant