Commit beb5f622 authored by POTTIER Francois's avatar POTTIER Francois

New test of [mapreduce].

parent 25828de8
type 'info expr_node =
| EConst of (int[@opaque])
| EAdd of 'info expr * 'info expr
and 'info expr =
{ info: 'info; node: 'info expr_node }
[@@deriving visitors { variety = "mapreduce" }]
open Expr_info_mapreduce
open Expr_info_mapreduce_use
let mk node = { info = (); node }
let const i =
mk (EConst i)
let add e1 e2 =
mk (EAdd (e1, e2))
let e =
add (const 1) (add (const 0) (const 3))
let (e : int expr) =
annotate e
let () =
assert (e.info = 5);
begin match e.node with
| EAdd (e1, e2) ->
assert (e1.info = 1);
assert (e2.info = 3);
()
| EConst _ ->
assert false
end;
Printf.printf "OK\n%!";
()
open Expr_info_mapreduce
let annotate (e : _ expr) : int expr =
let v = object
inherit [_] mapreduce as super
inherit [_] VisitorsRuntime.addition_monoid
method! visit_expr env { info = _; node } =
let node, size = super#visit_expr_node env node in
let size = size + 1 in
{ info = size; node }, size
method visit_'info _env _info =
assert false (* never called *)
end in
let e, _ = v # visit_expr () e in
e
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment