Module Type Signature Link

I am trying to reference a type in a module signature to create another type.

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

When I compile this, I get a "Error: Unbound module Cipher" message for self_t. I'm not too sure what to do here.

+4
source share
1 answer

In short, you should use Cipher_impl.local_tinsteadCipher.local_t

A module type (aka signature) is just a specification of a module interface. When you need a type, you need to refer to a specific type in a specific module, not in a signature.

+4
source

Source: https://habr.com/ru/post/1624114/


All Articles