-
-
Save Pitometsu/33e394c9b50a8259bbf3ecbb1c0c2599 to your computer and use it in GitHub Desktop.
OCaml Existential & Universal quantifications correlation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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