Skip to content

Instantly share code, notes, and snippets.

@EduardoRFS
Created April 13, 2021 18:06
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 EduardoRFS/1a7ab01c459b322e5535114a9271ca78 to your computer and use it in GitHub Desktop.
Save EduardoRFS/1a7ab01c459b322e5535114a9271ca78 to your computer and use it in GitHub Desktop.
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