Skip to content

Commit 0f95bfb

Browse files
committed
add atd wrapper for hash tables
1 parent 929b2a2 commit 0f95bfb

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

lib/common.atd

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
11
type 'v map_as_object =
22
(string * 'v) list <json repr="object">
33
wrap <ocaml module="Common.StringMap" t="'v Common.StringMap.t">
4+
5+
type 'v table_as_object =
6+
(string * 'v) list <json repr="object">
7+
wrap <ocaml module="Common.Table" t="'v Common.Table.t">

lib/common.ml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,20 @@ module StringMap = struct
1515
let unwrap = to_list
1616
end
1717

18+
module Table = struct
19+
type 'a t = (string, 'a) Hashtbl.t
20+
21+
let empty () = Hashtbl.create (module String)
22+
23+
let to_list (l : 'a t) : (string * 'a) list = Hashtbl.to_alist l
24+
25+
let of_list (m : (string * 'a) list) : 'a t = Hashtbl.of_alist_exn (module String) m
26+
27+
let wrap = of_list
28+
29+
let unwrap = to_list
30+
end
31+
1832
let fmt_error fmt = Printf.ksprintf (fun s -> Error s) fmt
1933

2034
let first_line s =

0 commit comments

Comments
 (0)