Skip to content

Instantly share code, notes, and snippets.

@Gbury
Last active February 7, 2017 15:22
Show Gist options
  • Save Gbury/ec790d93bebdca7605cc99926c558518 to your computer and use it in GitHub Desktop.
Save Gbury/ec790d93bebdca7605cc99926c558518 to your computer and use it in GitHub Desktop.
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