简体   繁体   English

ocaml GADT:为什么需要“输入a。”?

[英]ocaml GADT : why “type a.” needed?

In the basic example of GADT from§7.20 of ocaml manual , what is the meaning of 'type a.' ocaml手册第 7.20节的GADT基本示例中,'type a'的含义是什么? ? Why declaring "eval : a term -> a" is not enough ? 为什么宣称“eval:一个术语 - > 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)

Jacque's slide on ML'2011 workshop has a nice introduction. Jacque在ML'2011研讨会上的幻灯片有一个很好的介绍。 The idea to use syntax of locally abstract type to introduce universal expression-scoped variable. 使用本地抽象类型的语法来引入通用表达式范围变量的想法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM