Last active
February 7, 2017 15:22
-
-
Save Gbury/ec790d93bebdca7605cc99926c558518 to your computer and use it in GitHub Desktop.
This file contains 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 Id : sig | |
type 'a t | |
val hash : 'a t -> int | |
val equal : 'a t -> 'a t -> bool | |
val create : 'a -> 'a t | |
end = struct | |
type 'a t = { | |
id : int; | |
contents : 'a; | |
} | |
let create = | |
let r = ref 0 in | |
(fun contents -> incr r; { id = !r; contents; }) | |
let hash { id; _ } = id | |
let equal a b = a.id = b.id | |
module Int = struct | |
type nonrec t = int t | |
let hash = hash | |
let equal = equal | |
end | |
end | |
(* This works, but is quite verbose *) | |
module H = Hashtbl.Make(Id.Int) | |
(* Is there a nicer way to specialize a module defining a parametric type ? *) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment