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