小编Haj*_*hem的帖子

Ocaml:在模块之间传递构造函数类型

我有这个模块类型:

module type MOD =    
  sig   
    type operand
    type op
    val print : op -> string
  end;;
Run Code Online (Sandbox Code Playgroud)

MOD的实现是:

module M1:MOD =
  struct
    type operand = Mem of int | Reg of int | Const of int
    type op = Add of operand * operand| Sub of operand * operand
    let print op = match op with
      | Add _ -> "Add"
      | Sub _ -> "Sub"
  end;;
Run Code Online (Sandbox Code Playgroud)

我想创建一个参数化模块,op从第一个模块获取类型,并在该类型的变量上实现函数.像这样:

module  ARCHI = functor (M : MOD) ->
  struct
    type …
Run Code Online (Sandbox Code Playgroud)

ocaml types module abstract

4
推荐指数
1
解决办法
2241
查看次数

标签 统计

abstract ×1

module ×1

ocaml ×1

types ×1