Module 受子签名约束的OCaml子模块
我有一个模块Module 受子签名约束的OCaml子模块,module,ocaml,Module,Ocaml,我有一个模块Mod,它受签名Sig的约束。该模块有一个嵌套的子模块。签名有一个匹配的嵌套的子签名: module type Sig = sig val a : int module type Nested = sig val b : int end end module Mod : Sig = struct let a = 1 module Nested = struct let b = 2 end end 但是,这会产生以下错误: Error: Si
Mod
,它受签名Sig
的约束。该模块有一个嵌套的子模块。签名有一个匹配的嵌套的子签名:
module type Sig = sig
val a : int
module type Nested = sig
val b : int
end
end
module Mod : Sig = struct
let a = 1
module Nested = struct
let b = 2
end
end
但是,这会产生以下错误:
Error: Signature mismatch:
Modules do not match:
sig val a : int module Nested : sig val b : int end end
is not included in
Sig
The field `Nested' is required but not provided
我遗漏了什么?在代码中声明嵌套模块的方式是错误的:
module type Sig = sig
val a : int
module Nested : sig val b : int end
end
module Mod : Sig = struct
let a = 1
module Nested = struct
let b = 2
end
end
在以下链接中查看子模块是如何声明的:
这有助于我纠正你的错误