我在定义仿函数返回的模块类型时遇到问题。任何人都可以解决这个问题吗?
module type ANIMALTYPE = sig
val age : unit -> int
end
module type SHIPGENERATOR = sig
val age : unit -> int
(* Another possibility: include ANIMALTYPE *)
val hello : string
end
module RabbitModule : ANIMALTYPE = struct
let age () = 10
end
module Make_ShipGenerator (A : ANIMALTYPE) = struct
let age = A.age
let hello = "world"
end
let get_shipgenerator race = match race with
| Rabbit -> let module M = (Make_ShipGenerator (RabbitModule))
in (module M : SHIPGENERATOR)
修改:将hello
添加到Make_ShipGenerator
。
修改2 :添加了模块类型SHIPGENERATOR
,其中包含ANIMALTYPE
所需的部分。
答案 0 :(得分:0)
嗯,它是ANIMALTYPE
,还有什么?
let module M = (Make_ShipGenerator (RabbitModule))
in (module M : ANIMALTYPE);;