Ocaml 我可以在一个模块中使用2个sig吗?
我想在OCaml中创建数据库和表数据类型。我可以在1个模块中使用2个Ocaml 我可以在一个模块中使用2个sig吗?,ocaml,Ocaml,我想在OCaml中创建数据库和表数据类型。我可以在1个模块中使用2个sig关键字吗?您能否举例说明如何编写签名以及如何实现签名?如果您指的是一个满足两种模块类型的模块,是的,您可以 module type ADDITIVE = sig type t val add : t -> t -> t end module type MULTIPLICATIVE = sig type t val multiply : t -> t -> t end
sig
关键字吗?您能否举例说明如何编写签名以及如何实现签名?如果您指的是一个满足两种模块类型的模块,是的,您可以
module type ADDITIVE = sig
type t
val add : t -> t -> t
end
module type MULTIPLICATIVE = sig
type t
val multiply : t -> t -> t
end
module Number : sig
include ADDITIVE
include MULTIPLICATIVE with type t := t
end = struct
type t = int
let add x y = x + y
let multiply x y = x + y
end
我们说模块
编号
的签名包括模块类型加法
(在该上下文中打开t
)和乘法
,在加法
的t
中具有相同类型,因此,我们可以根据签名来实现该模块。尝试时会发生什么?请发布您尝试的代码以及编译器对它的说明。我不知道我对ocaml非常陌生,也没有实现代码的其余部分来确定它是否有效。感谢Marcelo的深入回答!!