我对OCaml模块相当陌生,使用自己的模块时我没有成功地将"include"和"open"分开使用。我试过把签名放在单独的.mli文件中,但没有成功。
下面是一个最小(不)工作示例,我正在尝试编译它:
ocamlc -o main Robot.ml main.ml
我应该怎么做才能只使用"open"或者只使用"include",而不是同时使用它们?
文件"Robot.ml":
module type RobotSignature =
sig
val top: unit -> unit
end
module Robot =
struct
let top () =
begin
Printf.printf "top\n"
end
(* Should not be visible from the 'main' *)
let dummy () =
begin
Printf.printf "dummy\n"
end
end
无法工作的文件"main.ml":
open Robot;;
top();
文件 "main.ml"(正在工作):
include Robot;;
open Robot;;
top();
open
的作用,请不要使用它,因为它会使你的代码难以理解。 - Daniel Bünzli