Module Ocaml值与模块中的参数化类型和签名不匹配
我正在尝试执行中的一个扩展练习,并将Module Ocaml值与模块中的参数化类型和签名不匹配,module,polymorphism,ocaml,Module,Polymorphism,Ocaml,我正在尝试执行中的一个扩展练习,并将int\u t类型替换为'a repr。在尝试执行此操作时,我遇到了以下错误: Values do not match: val cons : '_a repr -> '_a list_t -> '_a list_t is not included in val cons : 'a repr -> 'a list_t -> 'a list_t 我的cons实现如下 let cons: 'a repr -> 'a list
int\u t
类型替换为'a repr
。在尝试执行此操作时,我遇到了以下错误:
Values do not match:
val cons : '_a repr -> '_a list_t -> '_a list_t
is not included in
val cons : 'a repr -> 'a list_t -> 'a list_t
我的cons
实现如下
let cons: 'a repr -> 'a list_t -> 'a list_t =
liftm2 (fun h t -> h::t)
这肯定是正确的类型。为什么这些明显相同的类型不兼容?举一个简单的例子帮助我解决了这个问题! 我能够将失败的案例归结为:
module type Test = sig
type 'a t
val id: 'a t -> 'a t
end
module TestT: Test = struct
type 'a t = 'a
let id_maker () x = x
let id: 'a t -> 'a t =
id_maker ()
end
这表明我是受害者。
在中也有类似的问题,但模块错误消息误导了我。
我通过从
let cons: 'a repr -> 'a list_t -> 'a list_t =
liftm2 (fun h t -> h::t)
到
let cons: 'a repr -> 'a list_t -> 'a list_t =
fun h t -> liftm2 (fun h t -> h::t) h t