Does OCaml have an equivalent (possibly involving a camlp4 directive) of
from module import value1, value2
in Python or
use Module qw[value1 value2];
in Perl ?
I'd like to be able to write something like
open Ctypes (@->), string;;
or open Ctypes ((@->), string);;
instead of
let (@->) = Ctypes.(@->);;
let string = Ctypes.string;;
The closest is:
let value1, value2 = Module.(value1, value2)
For this very reason, open statements are most of the time evil (especially at the top level).
I'm afraid there is no such partial module opening like what you described.
If your modules have no naming conflict, then it's simple enough to just use open Ctypes
Otherwise, you can shorten the module name by
module CT = Ctypes
(* and then just call CT.some_function instead of Ctypes.some_function *)
Your solutions is quite a neat one, but be careful that the name string
may override the primitive type string
of OCaml.
let (@->) = Ctypes.(@->);;
let string = Ctypes.string;; (* override the type string *)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With