Caml Light manual提到可变的变量类型第37页:OCaml的可变变量类型
type foo = A of mutable int
| B of mutable int * int
但是这个扩展似乎并没有被OCaml中的一部分,是这样吗? 我是对的吗?在OCaml中定义可变类型的唯一方法是使用可变记录或数组?
(* with records *)
type a = {mutable a: int}
and b = {mutable b1: int; mutable b2: int}
and foo = A of a
| B of b
(* with arrays *)
type foo = A of int array
| B of int array
编辑:感谢@gasche建议使用裁判,这是可变的记录的快捷方式:
type foo = A of int ref
| B of int ref * int ref