Closed ulugbekna closed 3 years ago
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:
let x
as a shortcut for let x = x
, and we already allow { M.x }
to mean {x = M.x}
(record field punning). Maybe it would make sense to ask for module 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.).include Protocol
or open 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! :-)
One often needs to export a module imported from another module, e.g.,
I think this could be solved by this ppx by something like
My use-case is to avoid this: