Annotating by an existential type

You can bind the existentials in a GADT constructor as follows:

let update_afoo : afoo -> afoo = fun x ->
  let A (type a) (y : a foo) = x in
  let z : a foo = match y with Bar i -> Bar (i+1) | Baz s -> Baz (s ^ "1") in
  A z

See OCaml - Generalized algebraic datatypes.

Cheers,
Nicolas

7 Likes