Caml Light のマニュアルでは、可変バリアント型について 37 ページで言及しています。
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