paurkedal/ppx_regexp

Implicitly `let open Tyre` within [%tyre]

kevinji opened this issue · 3 comments

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

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.

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.

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