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
31
32
33
34
35
[@@@ocaml.warning "-32"]
type t =
| Harmless
| Mostly_harmless
| Average
| Above_average
| Dangerous
[@@deriving ord, enum]
[@@@ocaml.warning "+32"]
let to_string = function
| Harmless -> "harmless"
| Mostly_harmless -> "mostly-harmless"
| Average -> "average"
| Above_average -> "above-average"
| Dangerous -> "dangerous"
let pp = Fmt.of_to_string to_string
let values =
let rec aux i =
match of_enum i with
| Some l -> l :: aux (i + 1)
| None -> []
in
aux min
let of_string x =
match List.find_opt (fun l -> to_string l = x) values with
| Some x -> Ok x
| None ->
Fmt.error_msg "Unknown level %S; expected one of %a" x
Fmt.(list ~sep:(any ", ") pp) values