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

Simplify type variables #1263

Closed
wants to merge 4 commits into from
Closed

Conversation

Halbaroth
Copy link
Collaborator

This PR changes three thing:

  1. We do not need a value field in the type variable of Alt-Ergo. These values were only used by the unification of the
    types in the legacy typechecker.
  2. Add a proper type of the substitution of types in Ty. I add two different functions in the new module Subst to update a substitution. The function Subst.update updates a substitution without checking if it is compatible with a previous bind in the map. The function Subst.try_bind updates a substitution too but raises TypeClash if a previous bind in the map is incompatible with the new value.
  3. Use directly type variables from Dolmen. Notice that I didn't remove some caches in Translate for type variables but I think we can simplify this part too. I prefer doing it in a separate PR.

Copy link
Collaborator

@bclement-ocp bclement-ocp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I started the review but I think that while I agree with points 1 and 3 in the description (removing mutability, using Dolmen variables), I don't think point 2 is a good idea.

Substitutions are well understood as maps from variables to terms and I think we should just use that; wrapping that in a module with a hard-to-understand interface (try_bind) seems to only bring unneeded complexity.

Can you update the PR to remove the Subst module and I'll finish my review (I think most of the comments were going to be about that module anyway)?

src/lib/structures/ty.ml Show resolved Hide resolved
Comment on lines +208 to +218
val try_bind : tvar -> t -> subst -> subst
(** [try_bind tv ty sbt] tries to bind [tv] with [ty]. The function
succeeds if [tv] is not in the domain of [sbt] or the current
value of [tv] in [sbt] is equal to [ty].

If the current value of [tv] is not compatible with [ty], raises
the exception {!exception TypeClash}.

If the previous value of [tv] in [sbt] is equal to [ty] for [equal],
the returned substitution is physically equal to [sbt]. *)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could be made much simpler by simply exposing a function find that raises Not_found if the variable is not in the substitution.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, we do not need to expose this function because it is only used in the matching function of Ty. So we can use directly the find function.

@Halbaroth
Copy link
Collaborator Author

I started the review but I think that while I agree with points 1 and 3 in the description (removing mutability, using Dolmen variables), I don't think point 2 is a good idea.

Substitutions are well understood as maps from variables to terms and I think we should just use that; wrapping that in a module with a hard-to-understand interface (try_bind) seems to only bring unneeded complexity.

Can you update the PR to remove the Subst module and I'll finish my review (I think most of the comments were going to be about that module anyway)?

During the last dev meeting, we agreed that this modification was not appropriate. As often, the mathematical way to present a data structure is not the best way to implement it. It is common to consider a substitution as a total map from as set V to a superset E (here V = variables and E = expressions). After pushing this PR, I notices that this modification cannot be done for expression substitutions too because currently AE term variables are not typed, so we have no canonical injection between term variables and terms.

@Halbaroth
Copy link
Collaborator Author

Close in favor of #1267

@Halbaroth Halbaroth closed this Nov 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants