Skip to content

New version of pattern open, separating local equations in Env.t#578

Closed
garrigue wants to merge 8 commits intoocaml:trunkfrom
garrigue:pattern_open
Closed

New version of pattern open, separating local equations in Env.t#578
garrigue wants to merge 8 commits intoocaml:trunkfrom
garrigue:pattern_open

Conversation

@garrigue
Copy link
Contributor

@garrigue garrigue commented May 9, 2016

This is a new branch of GPR #187, which reduces the amount of changes by putting local constrains in a specific field of Env.t rather than mixing them with types.
This should help for other extensions.

Note that a large part of the changes are due to commit 68fdc8a, adding a compare function to the Path module, which should have been done ages ago :)

Octachron and others added 7 commits May 5, 2016 21:32
During type unification and pattern typing in presence of GADTs, it is
useful to be able to share type equalities. Before this commit, this
was done by using a environment reference to modify the environment
when needed.

However, that made impossible to locally update the environment without
either losing the shared reference or propagating globally the changes.
This is problematic for local opens in pattern that need to introduce
new identifiers in the environment for the sake or name lookup but only
within a limited scope. This commit introduces an `Env.mut` type to fix
this limitation in preparation of local open in pattern.
This commits extends the pattern syntax to support local open in
patterns. Four new constructions mirroring the expression constructions
are added

    * `M.(pattern)`
    * `M.[pattern_list]` ⟺ M.([pattern_list])
    * `M.{labeled_pattern_list}` ⟺ M.({label_pattern_list})
    * `M.[| .. |] ⟺ M.( [| .. |] )

At the typing phase, the construction `M.(pattern)` brings all
identifiers defined within M inside the scope and then proceed with the
typing of `pattern`. All others constructions are desugared to the
`M.(..)` construction during parsing.

Questionable implementation details:
* Currently, the local pattern open use the `type_open` function like
the local expression pattern. However, this implies that values defined
inside `M` are also brought to the scope. A specialized
`type_open_for_pattern` would be more efficient.
@garrigue garrigue mentioned this pull request May 9, 2016
type t = Ident.t
let compare = compare
end)
module IdentSet = Set.Make(Ident)
Copy link
Contributor

Choose a reason for hiding this comment

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

Ident.Set ? (added with all the Identifiable stuff with flambda)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fine, but this is completely orthogonal (the code was already there).

@alainfrisch
Copy link
Contributor

Currently, the constraints are only on simple identifiers, not qualified paths, right? I guess you directly introduced a PathMap to support gadt constraints on non-local abstract types (for http://caml.inria.fr/mantis/view.php?id=7233 ). Is that right?

@garrigue
Copy link
Contributor Author

garrigue commented May 9, 2016

Yes, and this is also needed for modular implicits.
But I'm not sure it is that easy... currently this only works for find_type, not lookup_type.
A solution would be to always use find_type after lookup_type, like for lookup_module / find_module.
Will think about that later.

@gasche
Copy link
Member

gasche commented May 9, 2016

I merged in trunk ( 2d33e16 ), thanks!

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

Successfully merging this pull request may close these issues.

5 participants