Ocaml值与模块和签名中的参数化类型不匹配
问题描述:
我正在尝试执行http://okmij.org/ftp/tagless-final/nondet-effect.html#no-functor中的一个扩展练习并将int_t
类型替换为'a repr
。尽管试图做到这一点,我卡上看到以下错误:Ocaml值与模块和签名中的参数化类型不匹配
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
这表明我的牺牲品value restriction。 this other stack overflow question有类似的问题,但我被模块错误消息误导。 我通过从
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
固定的问题