import a module to re-export it
Closed this issue · 4 comments
One often needs to export a module imported from another module, e.g.,
(* m0.ml *)
module M = struct end
(* m1.ml *)
(* wants to re-export [M0.M] as [M] now: *)
module M = M0.M
I think this could be solved by this ppx by something like
[%%import M0.M] (* that could be expanded to module M = M0.M *)
My use-case is to avoid this:
module Capability = Capability
module Proto_request = Protocol.Proto_request
module Advertised_refs = Protocol.Advertised_refs
module Want = Protocol.Want
module Result = Protocol.Result
module Negotiation = Protocol.Negotiation
module Shallow = Protocol.Shallow
module Commands = Protocol.Commands
module Status = Protocol.Status
Hi @ulugbekna! I am not too enthusiastic about your feature suggestion, because to me it falls outside the scope of ppx_import
. The job of ppx_import
is to lookup the full definition of an OCaml object defined elsewhere, for the purpose of facilitating "derived" definitions, metaprograms that inspect the full definition. What you propose is more of a syntactic convenience that is easily expanded locally, it has a different purpose.
Two remarks:
- It was recently proposed to allow
let x
as a shortcut forlet x = x
, and we already allow{ M.x }
to mean{x = M.x}
(record field punning). Maybe it would make sense to ask formodule Protocol.Want
. But there is not much enthusiasm for syntactic extensions that are purely for local convenience (they have a cost in implementation, documentation, tooling etc.). - Why not just
include Protocol
oropen Protocol
?
Hi Gabriel! Thanks for your reply.
I was under impression that the behavior that I described fit into the semantics of word "import" and use-case similar to keywords "import" in Scala or python.
open
populates the environment with more values from Protocol
than I would like to.
[%import Package.User] (* to be able to just use an alias module [User]; similar to Scala's [import Package.User] *)
(* or *)
[%import Package.User as U] (* module U = Package.User *)
(* or *)
[%import Package.User.{login, password} (* let login = Package.User.login;; let password = Package.User.password *)
(* or *)
[%import Package.User.{login, password} as U (*
module U = struct
let login = Package.User.login;; let password = Package.User.password;;
end *)
*)
I was under impression that the behavior that I described fit into the semantics of word "import" and use-case similar to keywords "import" in Scala or python.
Yes, but the purpose of ppx_import
is not to provide an "import" feature as in these languages for OCaml users (or in general to provide any sort of syntactic language features), but really to enable other extensions to do meta-programming on external/imported definitions.
Thanks for consideration! :-)