Skip to content

Commit 578a194

Browse files
committed
[lib] Add to_list and of_list to MyMap
Those functions are only supported after ocaml 5.
1 parent b521311 commit 578a194

2 files changed

Lines changed: 8 additions & 2 deletions

File tree

gen/top_gen.ml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -900,8 +900,7 @@ let max_set = IntSet.max_elt
900900
let locs = List.split inits |> fst |> A.LocSet.of_list in
901901
let extra_type_declaration =
902902
A.LocMap.filter ( fun k _ -> not @@ A.LocSet.mem k locs ) env
903-
(* to_list only exists after ocaml 5 *)
904-
|> A.LocMap.to_seq |> List.of_seq
903+
|> A.LocMap.to_list
905904
(* give default 0 value *)
906905
|> List.map ( fun (loc, t) -> (loc, (typ_to_testtype t, A.S "0")) ) in
907906
List.sort (fun (l, _) (r, _) -> A.location_compare l r) (type_inits @ extra_type_declaration)

lib/myMap.ml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@ module type S = sig
5151
(* Bind keys to list of values *)
5252
val accumulate : key -> 'a -> 'a list t -> 'a list t
5353

54+
(* `to_list` and `of_list` are only supported since 5.1 *)
55+
val to_list : 'a t -> (key * 'a) list
56+
val of_list : (key * 'a) list -> 'a t
57+
5458
end
5559

5660
module Make(O:Set.OrderedType) : S with type key = O.t =
@@ -109,4 +113,7 @@ module Make(O:Set.OrderedType) : S with type key = O.t =
109113
| Some vs -> Some (v::vs))
110114
m
111115

116+
let to_list m = M.to_seq m |> List.of_seq
117+
let of_list m = List.to_seq m |> M.of_seq
118+
112119
end

0 commit comments

Comments
 (0)