File: oexpr_polymorphic.ml

package info (click to toggle)
ocaml-visitors 20200210-3
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 1,896 kB
  • sloc: ml: 4,077; makefile: 44; sh: 18
file content (21 lines) | stat: -rw-r--r-- 431 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
(* Defining open expressions
   and closing them,
   in one go,
   in [polymorphic] mode. *)

type 'expr oexpr =
  | EConst of int
  | EAdd of 'expr * 'expr

and expr =
  E of expr oexpr [@@unboxed]

[@@deriving visitors { variety = "map"; polymorphic = true; concrete = true }]

let double : expr -> expr =
  let v = object
    inherit [_] map
    method! visit_EConst _ _env k =
      EConst (2 * k)
  end in
  v # visit_expr ()