Last active
March 13, 2025 05:37
-
-
Save brendanzab/c641c04b63935367d9298e7a4e2c6757 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 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