Skip to content

Instantly share code, notes, and snippets.

@rand00
Last active October 22, 2016 19:24
Show Gist options
  • Save rand00/d97025b5da82809dbb46a3be39753840 to your computer and use it in GitHub Desktop.
Save rand00/d97025b5da82809dbb46a3be39753840 to your computer and use it in GitHub Desktop.
Hiding private variants v1
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