Last active
October 22, 2016 19:24
-
-
Save rand00/d97025b5da82809dbb46a3be39753840 to your computer and use it in GitHub Desktop.
Hiding private variants v1
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
module type S = sig | |
type priv | |
type exposed = [ `A | `Priv of priv ] | |
val mkB : unit -> priv | |
val f : priv -> priv | |
val g : priv -> string | |
val extract : priv -> exposed | |
val inject : exposed -> priv | |
end | |
module M : S = struct | |
type priv = [ | |
`A | `B | `C | |
] | |
let mkB () = `B | |
let f = function | |
`A -> `B | |
| `B -> `C | |
| `C -> `A | |
let g = function | |
`A -> "A" | |
| `B -> "B" | |
| `C -> "C" | |
type exposed = [ `A | `Priv of priv ] | |
let extract = function | |
| `A -> `A | |
| p -> `Priv p | |
let inject = function | |
| `A -> `A | |
| `Priv p -> p | |
end | |
let _ = | |
M.( inject (`Priv (mkB ())) |> f |> g) | |
|> print_endline |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment