ocaml - 引用模块类型签名

标签 ocaml

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

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;
  }

当我编译这个时,我得到 self_t 的“错误:未绑定(bind)模块密码”。我不太确定在这里做什么。

最佳答案

简而言之,您应该使用 Cipher_impl.local_t而不是 Cipher.local_t
模块类型(又名签名)只是模块接口(interface)的规范。当您需要一个类型时,您需要在特定模块中引用特定类型,而不是在签名中。

关于ocaml - 引用模块类型签名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34768230/

相关文章:

types - 具有参数类型的第一类模块(类型构造函数 F.f 将逃脱其范围)

scala - 用于 Ocaml 和其他语言的基于 Actor 的分布式并发库

ocaml - 有没有办法在 OCaml 沙丘中用连字符声明可执行文件?

ocaml - 平方和的总和 OCaml

functional-programming - 如何组合相等的序列元素(函数式编程)?

list - OCaml 有像 Haskell 的++ 那样的语法吗?

ocaml - 返回列表中所有值的递归函数(在 OCaml 中)

Ocaml 变体类型

ocaml - js_of_ocaml 和核心

exception - 不能仅在 mli 文件中定义异常