Created
July 26, 2015 18:49
-
-
Save gsg/9e810663abc5e7049321 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
type (_,_) equality = Refl : ('a,'a) equality | |
module EqTag : sig | |
type 'a t | |
val create : unit -> 'a t | |
val equal : 'a t -> 'b t -> ('a, 'b) equality option | |
end = struct | |
type 'a tag = ..;; | |
type 'a polymorphic_equality = { | |
eq : 'b . ('a tag -> 'b tag -> ('a, 'b) equality option); | |
} | |
type 'a t = 'a tag * 'a polymorphic_equality | |
let create (type s) () = | |
let module M = struct | |
type _ tag += Tag : (s, s) equality -> s tag | |
let eq : type a b . a tag -> b tag -> (a, b) equality option = | |
fun a b -> | |
match a, b with | |
| Tag x, Tag _ -> Some x | |
| _, _ -> None | |
end in | |
M.Tag Refl, {eq = M.eq} | |
let equal (tag1, {eq}) (tag2, _) = eq tag1 tag2 | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment