Types OCaml函子与类型问题

Types OCaml函子与类型问题,types,ocaml,functor,Types,Ocaml,Functor,由于无法使用Elt.t,如何引用FOOable定义的类型'a t 因此,在本例中,它将变成type'at='a列表 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

由于无法使用
Elt.t
,如何引用
FOOable
定义的类型
'a t

因此,在本例中,它将变成
type'at='a列表

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 Elt.t
,就一定能找到正确的类型

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

请注意,正如在
FOO_FUNCTOR
的定义中一样,类型相等是隐藏的,
'a t
'a Elt.t
之间的链接在
MakeFOO
定义之外将不可见(但这可能是您正在寻找的).

您只需键入
'a Elt.t
,就一定能找到正确的类型

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
请注意,正如在
FOO_FUNCTOR
的定义中一样,类型相等是隐藏的,
'a t
'a Elt.t
之间的链接在
MakeFOO
定义之外将不可见(但这可能是您正在寻找的)