Source

pa_ovisitor / pa / test / test_iter.ml

Full commit
let sum = ref 0 

type 'a t = 
  | Foo of int list 
  | Bar of int * int * 'a
with ovisit

class o' = object (self:'self)
  inherit ovisit_t
  val mutable st = 0
  method st = st
  method int n = st <- st + n
  method list = List.iter
  method unit () = ()
end


let _ = 
  let v = new o' in
  v#t v#int (Foo [ 1; 2; 3; 4; 5 ]);
  assert (v#st = 15);
  let v = new o' in
  v#t v#int (Bar (1, 2, 3));
  assert (v#st = 6);
  let v = new o' in
  v#t v#unit (Bar (1,2,()));
  assert (v#st = 3)