1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
module type S = sig
include Set.S
val to_yojson : t -> Yojson.Safe.t
val of_yojson : Yojson.Safe.t -> (t, string) CCResult.t
val pp : Format.formatter -> t -> unit
end
module Make (R : Role.Sig) : S with type elt = R.t = struct
include Set.Make (R)
let to_yojson t = `List (CCList.map R.to_yojson (elements t))
let of_yojson =
let open CCResult in
function
| `List items ->
CCList.fold_left
(fun acc x ->
acc >>= fun acc' -> x |> R.of_yojson >|= CCFun.flip add acc')
(Ok empty)
items
| _ -> Error "Invalid role set"
;;
let pp fmt t =
let show = [%show: R.t list] in
Format.fprintf fmt "[%s]" (show (elements t))
;;
end