Say we want to create an infix operator @ in Pervasives module for List.append, so we can conveniently append lists in whatever source file (Pervasives is automatically loaded).
Now we have 2 choices:
let (@) = List.append
or
let rec (@) xs ys =
match xs with
| [] -> ys
| x::xs -> x::(xs @ ys)
;;
Either one creates a cyclic dependency Pervasives -> List -> Pervasives.
The root of this problem is that, to be loaded automatically into every module, Pervasives must not depend on any other module, else there would be a cyclic dependency Pervasives -> X -> Pervasives.
But we do want some values in Pervasives for convenience. Can we do it with acceptable costs?
The way OCaml's compiler does it is by adding built-in types such as list and option. See ocaml/typing/predef.mli for details.
I think it's a decent solution, slightly annoying that we can't define everything in source code, but not too bad in my opinion.
Say we want to create an infix operator
@
inPervasives
module forList.append
, so we can conveniently append lists in whatever source file (Pervasives
is automatically loaded).Now we have 2 choices:
or
Either one creates a cyclic dependency
Pervasives -> List -> Pervasives
.The root of this problem is that, to be loaded automatically into every module,
Pervasives
must not depend on any other module, else there would be a cyclic dependencyPervasives -> X -> Pervasives
.But we do want some values in
Pervasives
for convenience. Can we do it with acceptable costs?The way OCaml's compiler does it is by adding built-in types such as
list
andoption
. Seeocaml/typing/predef.mli
for details.I think it's a decent solution, slightly annoying that we can't define everything in source code, but not too bad in my opinion.