Skip to content

Instantly share code, notes, and snippets.

@gsg
Created November 27, 2014 17:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gsg/0375debe0d93974c252d to your computer and use it in GitHub Desktop.
Save gsg/0375debe0d93974c252d to your computer and use it in GitHub Desktop.
module rec Value : sig
type t =
| Nil
| Bool of bool
| Float of float
| String of string
| Table of table
and table = {
id : int;
table : t Table.t;
}
val hash : t -> int
val equal : t -> t -> bool
val make_table : unit -> table
end = struct
type t =
| Nil
| Bool of bool
| Float of float
| String of string
| Table of table
and table = {
id : int;
table : t Table.t;
}
let hash = Hashtbl.hash
let equal x y = match x, y with
| Nil, Nil -> true
| Bool x, Bool y -> x = y
| Float x, Float y -> x = y
| String x, String y -> x = y
| Table x, Table y -> x == y
| _, _ -> false
let make_table =
let count = ref 0 in
fun () -> incr count; { id = !count; table = Table.create 4; }
end
and Table : Hashtbl.S with type key = Value.t = Hashtbl.Make (Value)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment