Skip to content

Instantly share code, notes, and snippets.

@Pitometsu
Last active June 2, 2019 00:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Pitometsu/33e394c9b50a8259bbf3ecbb1c0c2599 to your computer and use it in GitHub Desktop.
Save Pitometsu/33e394c9b50a8259bbf3ecbb1c0c2599 to your computer and use it in GitHub Desktop.
OCaml Existential & Universal quantifications correlation
type 'x showable = 'x * ('x -> string);;
type showableE = ShowableE: 'x showable -> showableE;;
type showableU = { showableU : 'w. 'w showableU' -> 'w }
and 'w showableU' = { showableU' : 'x. 'x showable -> 'w };;
let e2u : showableE -> showableU = function ShowableE v -> { showableU = fun k -> k.showableU' v };;
let u2e : showableU -> showableE = function { showableU = f } -> f { showableU' = fun x -> ShowableE x };;
let showable = ("hello there", fun _ -> "any string you like");;
u2e @@ e2u ShowableE showable
e2u @@ u2e { showableU = function { showableU' = f } -> f showable };;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment