Quantcast
Channel: Active questions tagged ocaml - Stack Overflow
Viewing all articles
Browse latest Browse all 528

How to convert 'module type' with 'non-generic type' to 'module type' with 'generic type' by destructive substitution?

$
0
0

I have a module type with three non-generic types:

module type LAYER = sig  type cytoplasm_t  type nucleus_t  type t  val cytoplasm        : int -> t -> cytoplasm_t  val nucleus          : int -> t -> nucleus_t   val add_cytoplasm    : int -> cytoplasm_t -> t -> t  val add_nucleus      : int -> nucleus_t -> t -> t  val remove_cytoplasm : int -> t -> t  val remove_nucleus   : int -> t -> tend

I want to convert it to a module type with a generic nested type that has two type parameters instead of two non-generic types as it is in the source module type:

module type LAYER' = sig  type ('cytoplasm, 'nucleus) t  val cytoplasm        : int -> ('c, 'n) t -> 'c  val nucleus          : int -> ('c, 'n) t -> 'n   val add_cytoplasm    : int -> 'c -> ('c, 'n) t -> ('c, 'n) t  val add_nucleus      : int -> 'n -> ('c, 'n) t -> ('c, 'n) t  val remove_cytoplasm : int -> ('c, 'n) t -> ('c, 'n) t  val remove_nucleus   : int -> ('c, 'n) t -> ('c, 'n) tend

I tried to do that by 'include' with ':=' but failed:

module type LAYER' = sig  type ('c, 'n) t  include LAYER      with type t := ('c, 'n) t      and type nucleus_t := 'n      and type cytoplasm_t := 'cend 

Error: The type variable 'c is unbound in this type declaration

As I expected, destructive substitution doesn't work like replacement. I have a long list of functions in my real-life example, and this feature would be helpful for me. Is it possible to do that?


Viewing all articles
Browse latest Browse all 528

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>