ocaml GADT : why "type a." needed?

标签 ocaml gadt locally-abstract-type

在来自ocaml manual的§7.20 的 GADT 基本示例中,“类型a”是什么意思。 ? 为什么声明“eval : a term -> a”是不够的?

type _ term =
          | Int : int -> int term
          | Add : (int -> int -> int) term
          | App : ('b -> 'a) term * 'b term -> 'a term

        let rec eval : type a. a term -> a = function
          | Int n    -> n                 (* a = int *)
          | Add      -> (fun x y -> x+y)  (* a = int -> int -> int *)
          | App(f,x) -> (eval f) (eval x)

最佳答案

雅克的 slide on ML'2011 workshop 有一个很好的介绍。使用局部抽象类型语法引入通用表达式范围变量的想法。

关于ocaml GADT : why "type a." needed?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33314788/

相关文章:

OCAML hashtbl 删除特定绑定(bind)

Char 与 int 调用约定

types - 当 GADT 构造函数包含多个类型变量时,局部抽象类型的范围错误

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

ocaml - 来自外部的参数化 GADT

algorithm - 创建快速指数函数

pattern-matching - OCaml:匹配另一个表达式中的表达式?

haskell - 如何对 `Constraint` 类型的变量施加约束?

haskell - 为 Haskell GADT 定义 Eq 实例

ocaml - 在 OCaml 中创建 GADT 表达式