【发布时间】:2020-01-05 17:23:42
【问题描述】:
这是我的代码:
foo.ml:
module type ITy = sig
type ty
end
module type IFoo = sig
type ty
val doo: ty -> ty
end
module Make (Ty: ITy): IFoo = struct
type ty = Ty.ty
let doo (x:ty) = x
end
main.ml:
module MyFoo = Foo.Make(struct
type ty = int
end)
let () = assert(MyFoo.doo 3 = 3)
要编译,我使用:
$ corebuild main.native
这给了我:
+ ocamlfind ocamlc -c -w A-4-33-40-41-42-43-34-44 -strict-sequence -g -bin-annot -short-paths -thread -package core -ppx 'ppx-jane -as-ppx' -o main.cmo main.ml
File "main.ml", line 5, characters 26-27:
5 | let () = assert(MyFoo.doo 3 = 3)
^
Error: This expression has type int but an expression was expected of type
MyFoo.ty
Command exited with code 2.
Hint: Recursive traversal of subdirectories was not enabled for this build,
as the working directory does not look like an ocamlbuild project (no
'_tags' or 'myocamlbuild.ml' file). If you have modules in subdirectories,
you should add the option "-r" or create an empty '_tags' file.
To enable recursive traversal for some subdirectories only, you can use the
following '_tags' file:
true: -traverse
<dir1> or <dir2>: traverse
Compilation unsuccessful after building 4 targets (3 cached) in 00:00:01.
我希望我的代码能够成功编译 b.c。我是一个 OCaml 菜鸟,当我在 main.ml 中调用 Foo.Make 函子来创建 MyFoo 时,我给它一个输入结构 type ty = int。我可能做错了什么,但未能找到专门讨论此问题的文档。也许我在某处使用了错误的运算符。任何帮助将不胜感激。
【问题讨论】:
标签: ocaml