I’ve noticed that idiomatic OCaml does not seem to use qualified imports in code very much. Mostly there is the use of
open keyword in code or you may have something verbose like
Core_kernel.Map.empty (or shorter
In Haskell there are a lot of qualified imports so instead of
Core_kernel.Map.empty people might do a qualified import and subsequently refer to things with like
M.empty – the M serving as a reminder where the
empty function has come from.
You can emulate this in OCaml easily by doing:
module M = struct include Core_kernel.Map end ... (* possible to use M.empty now *) M.empty ...
Am I correct in my understanding?
Why aren’t qualified imports used more often? I can see this being useful in tutorials. A lot of tutorial code has a bunch of
opens and then its difficult to understand where things are coming from.
I am aware of the shortcut
Core_kernel.Map.( (* ocaml code here *) )
but it is not very satisfying to me.