1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
type ref 'a = < get : 'a; put : 'a -> unit >
and source +'a = < get : 'a >
and sink -'a = < put : 'a -> unit >
;
value ref x =
let r = ref x in
object
method get = r.val;
method put x = r.val := x;
end
;
value get (r : < get : 'a; .. > ) = r#get
;
value put (r : < put : 'a -> unit; .. > ) x = r#put x
;
value () =
let r = ref (`A : [= `A | `B]) in
( ignore (get (r :> source [= `A | `B | `C ]))
; ignore (put (r :> sink [= `A ]) `A)
)
;