Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
module type Show = sig
type t
val show: t -> string
end
let show (module S: Show) v = S.show v
module Show_option (S: Show) = struct
type t = S.t option
let show v =
match v with
| None -> "None"
| Some v -> Printf.sprintf "(Some %s)" (S.show v)
end
let x = show (
if Random.float(1.0) > 0.01 then
(module Show_option(struct
type t = int
let show = Printf.sprintf "%d"
end))
else
(module Show_option(struct
type t = int
let show v = Printf.sprintf "%d" (v - 1)
end))
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment