fold.ml 410 Bytes
Newer Older
POTTIER Francois committed
1 2 3 4 5 6 7 8 9 10 11
type person = {
  firstname: string[@opaque];
  surname:   string[@opaque]
}

and crowd =
  | Nobody
  | Someone of person * crowd
[@@deriving visitors { variety = "fold" }]

let convert : crowd -> (string * string) list =
12
  let v = object
13 14 15 16 17
    inherit [_] fold
    method build_person  () f s = (f, s)
    method build_Nobody  ()     = []
    method build_Someone () p c = p :: c
  end
18
  in v # visit_crowd ()