Comment detail

変数の初期値 (Nested Flatten)
refとoptionでシミュレート。
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
type 'a t = 'a option ref

let mkvar () = (ref None:'a t)
let get (x:'a t) = !x
let set_normal (x:'a t) y = (x := Some y)
let set_defor (x:'a t) y =
  match !x with
  | None -> x := Some y
  | Some _ -> ()

let (//=) = set_defor;;

(*
  let x = mkvar ();;
  x //= 1;  get x;; (* Some 1*)
  x //= 2;  get x;; (* Some 1*)
*)

Index

Feed

Other

Link

Pathtraq

loading...