paurkedal / ppx_regexp

Matching Regular Expressions with OCaml Patterns
GNU Lesser General Public License v3.0
57 stars 3 forks source link

Implicitly `let open Tyre` within [%tyre] #6

Closed kevinji closed 5 years ago

kevinji commented 5 years ago

Is it possible for the pattern within [%tyre] to be interpreted as if let open Tyre was run? It seems useful to have primitive Tyre types like Tyre.int be recognized by default.

Drup commented 5 years ago

I'm a bit afraid of shadowing user identifiers. It also means that introducing new base regexp in Tyre risk breaking user's code, which doesn't sound like a great idea.

paurkedal commented 5 years ago

I agree, local opens are problematic unless the opened module is very restrictive about the naming of identifiers it defines and may define in the future. And I don't see a way to emulate something like a non-shadowing open statement, which would push a module to the bottom of the search stack.

Thinking in the other direction of giving control of the namespace to the user, I am pondering about a way to register local opens in advance, like:

module Tyre_pervasives = struct
  let int = Tyre.int
  let float = Tyre.float
  let custom = ...
  ...
end
open%tyre Tyre_pervasives
...
let ... = ... [%tyre {|(?&int)|}%] ...

But this is still not ideal, since the scoping rules would be the same; local identifiers in the let body would be shadowed by Tyre_pervasives. I think the best option at the moment to avoid qualifying, is to define something like the above module per-project and open it outside the local scope. In a few cases identifiers like int might clash with other imports.

kevinji commented 5 years ago

That's fair, you all bring up good points that I didn't consider. I'll close this for now then.