module type FOOable = sig
type 'a t
val foo : 'a -> 'a t
end
module type FOO_FUCNTOR =
functor (Elt : FOOable) ->
sig
type 'a t
val foo_alias : 'a -> 'a t
(* ... *)
end
如何引用'a t
定义的FOOable
类型,因为无法使用Elt.t
?
因此,在此示例中,它将变为type 'a t = 'a list
module MakeFoo : FOO_FUNCTOR =
functor (Elt : FOOable) ->
struct
type 'a t = ??? (* I want the type 'a t belonging to Elt *)
let foo_alias = Elt.foo
end
module FooableList = struct
type = 'a list
let foo x = [x]
end
module FooList = MakeFoo(FooableList)
let a = FooList.foo_alias 2
答案 0 :(得分:4)
您只需输入'a Elt.t
,就可以确定参考正确的类型。
module MakeFoo : FOO_FUNCTOR =
functor (Elt : FOOable) ->
struct
type 'a t = 'a Elt.t
let foo_alias = Elt.foo
end
请注意,与FOO_FUNCTOR
的定义一样,隐藏了类型相等性,'a t
和'a Elt.t
之间的链接在MakeFOO
定义之外不可见(但是这可能就是你要找的东西。)