@@ -26,29 +26,34 @@ module Flag = struct
2626
2727 let o ~name ~default =
2828 let state =
29- try List. assoc name ! optims
30- with Not_found ->
31- let state = ref default in
32- optims := (name, state) :: ! optims;
33- state
29+ match List. string_assoc name ! optims with
30+ | Some x -> x
31+ | None ->
32+ let state = ref default in
33+ optims := (name, state) :: ! optims;
34+ state
3435 in
3536 fun () -> ! state
3637
3738 let find s =
38- try ! (List. assoc s ! optims)
39- with Not_found -> failwith (Printf. sprintf " The option named %S doesn't exist" s)
39+ match List. string_assoc s ! optims with
40+ | Some x -> ! x
41+ | None -> failwith (Printf. sprintf " The option named %S doesn't exist" s)
4042
4143 let set s b =
42- try List. assoc s ! optims := b
43- with Not_found -> failwith (Printf. sprintf " The option named %S doesn't exist" s)
44+ match List. string_assoc s ! optims with
45+ | Some s -> s := b
46+ | None -> failwith (Printf. sprintf " The option named %S doesn't exist" s)
4447
4548 let disable s =
46- try List. assoc s ! optims := false
47- with Not_found -> failwith (Printf. sprintf " The option named %S doesn't exist" s)
49+ match List. string_assoc s ! optims with
50+ | Some s -> s := false
51+ | None -> failwith (Printf. sprintf " The option named %S doesn't exist" s)
4852
4953 let enable s =
50- try List. assoc s ! optims := true
51- with Not_found -> failwith (Printf. sprintf " The option named %S doesn't exist" s)
54+ match List. string_assoc s ! optims with
55+ | Some s -> s := true
56+ | None -> failwith (Printf. sprintf " The option named %S doesn't exist" s)
5257
5358 let pretty = o ~name: " pretty" ~default: false
5459
@@ -107,13 +112,18 @@ module Param = struct
107112 let int default = default, int_of_string
108113
109114 let enum : (string * 'a) list -> _ = function
110- | (_ , v ) :: _ as l -> v, fun x -> List. assoc x l
115+ | (_ , v ) :: _ as l -> (
116+ ( v
117+ , fun x ->
118+ match List. string_assoc x l with
119+ | Some x -> x
120+ | None -> assert false ))
111121 | _ -> assert false
112122
113123 let params : (string * _) list ref = ref []
114124
115125 let p ~name ~desc (default , convert ) =
116- assert (not (List. mem_assoc name ~map: ! params));
126+ assert (Option. is_none (List. string_assoc name ! params));
117127 let state = ref default in
118128 let set : string -> unit =
119129 fun v ->
@@ -124,8 +134,9 @@ module Param = struct
124134 fun () -> ! state
125135
126136 let set s v =
127- try fst (List. assoc s ! params) v
128- with Not_found -> failwith (Printf. sprintf " The option named %S doesn't exist" s)
137+ match List. string_assoc s ! params with
138+ | Some (f , _ ) -> f v
139+ | None -> failwith (Printf. sprintf " The option named %S doesn't exist" s)
129140
130141 let all () = List. map ! params ~f: (fun (n , (_ , d )) -> n, d)
131142
0 commit comments