Skip to content

Instantly share code, notes, and snippets.

@brendanzab
Last active March 13, 2025 05:37
Show Gist options
  • Save brendanzab/c641c04b63935367d9298e7a4e2c6757 to your computer and use it in GitHub Desktop.
Save brendanzab/c641c04b63935367d9298e7a4e2c6757 to your computer and use it in GitHub Desktop.
module Option = struct
type 'a shape = [
| `Some of 'a
| `None
]
module type S = sig
type 'a t
val intro : 'a shape -> 'a t
val elim : 'a t -> ('a shape -> 'b) -> 'b
end
module Impl1 : S = struct
type 'a t = 'a shape
let intro opt = opt
let elim x k = k x
end
module Impl2 : S = struct
type 'a t =
| Some of 'a
| None
let intro = function
| `Some x -> Some x
| `None -> None
let elim = function
| Some x -> fun k -> k (`Some x)
| None -> fun k -> k `None
end
(* TODO: Impl that uses Stdlib.Obj *)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment