引用模块类型签名

referencing a module type signature

我试图在模块签名中引用一个类型来构建另一个类型。

module type Cipher = sig

  type local_t
  type remote_t

  val local_create : unit -> local_t
  val local_sign : local_t -> Cstruct.t -> Cstruct.t
  val remote_create : Cstruct.t -> remote_t
  val remote_validate : remote_t -> Cstruct.t -> bool

end

module Make_cipher :                                                              
  functor (Cipher_impl : Cipher) ->
    sig                                                                         
      type local_t = Cipher_impl.local_t                                        
      type remote_t = Cipher_impl.remote_t
      val local_create : unit -> local_t
      val local_sign : local_t -> Cstruct.t -> Cstruct.t
      val remote_create : Cstruct.t -> remote_t
      val remote_validate : remote_t -> Cstruct.t -> bool
    end

type self_t = 
  {
    mutable modules : (module Cipher) list;
    mutable locals : Cipher.local_t list;
  }

当我编译它时,我得到 'Error: Unbound module Cipher' for self_t。我不太确定在这里做什么。

简而言之,您应该使用 Cipher_impl.local_t 而不是 Cipher.local_t

模块类型(又名签名)只是模块接口的规范。当你需要一个类型时,你需要在特定模块中引用特定类型,而不是在签名中。