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