Stefan pushed to branch master at Stefan / Typer
Commits: a7bdf1e6 by Stefan Monnier at 2018-09-18T23:04:14Z Avoid the <foo>_opt functions not available in older OCaml
* src/util.ml (smap_find_opt): New function to replace SMap.find_opt.
* src/eval.ml (nth_ctor_arg.find_nth): Avoid List.nth_opt. (erasable_p2.is_erasable): Use List.exists.
- - - - -
2 changed files:
- src/eval.ml - src/util.ml
Changes:
===================================== src/eval.ml ===================================== @@ -778,7 +778,7 @@ let constructor_p name ectx = with Senv_Lookup_Fail _ -> false
let erasable_p name nth ectx = - let is_erasable ctors = match (SMap.find_opt name ctors) with + let is_erasable ctors = match (smap_find_opt name ctors) with | (Some args) -> if (nth < (List.length args) && nth >= 0) then ( match (List.nth args nth) with @@ -796,14 +796,14 @@ let erasable_p name nth ectx = with Senv_Lookup_Fail _ -> false
let erasable_p2 t name ectx = - let is_erasable ctors = match (SMap.find_opt t ctors) with - | (Some args) -> - ( match (List.find_opt (fun (k, oname, _) -> - match oname with - | (_, Some n) -> (n = name && k = Aerasable) - | _ -> false) args) with - | Some _ -> true - | _ -> false ) + let is_erasable ctors = match (smap_find_opt t ctors) with + | Some args -> + (List.exists + (fun (k, oname, _) + -> match oname with + | (_, Some n) -> (n = name && k = Aerasable) + | _ -> false) + args) | _ -> false in try let idx = senv_lookup t ectx in match OL.lexp_whnf (mkVar ((dummy_location, Some t), idx)) @@ -816,12 +816,13 @@ let erasable_p2 t name ectx = with Senv_Lookup_Fail _ -> false
let nth_ctor_arg name nth ectx = - let find_nth ctors = match (SMap.find_opt name ctors) with - | (Some args) -> - ( match (List.nth_opt args nth) with - | Some (_, (_, Some n), _) -> n - | _ -> "_" ) - | _ -> "_" in + let find_nth ctors = match (smap_find_opt name ctors) with + | Some args -> + (match (List.nth args nth) with + | (_, (_, Some n), _) -> n + | _ -> "_" + | exception (Failure _) -> "_" ) + | _ -> "_" in try let idx = senv_lookup name ectx in match OL.lexp_whnf (mkVar ((dummy_location, Some name), idx)) (ectx_to_lctx ectx) with @@ -837,7 +838,7 @@ let ctor_arg_pos name arg ectx = | [] -> None | (_, (_, Some x), _)::xs -> if x = arg then Some n else find_opt xs (n + 1) | _::xs -> find_opt xs (n + 1) in - let find_arg ctors = match (SMap.find_opt name ctors) with + let find_arg ctors = match (smap_find_opt name ctors) with | (Some args) -> ( match (find_opt args 0) with | None -> (-1)
===================================== src/util.ml ===================================== @@ -21,6 +21,10 @@ You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/. *)
module SMap = Map.Make (String) +(* Apparently OCaml-4.02 doesn't have find_opt and Debian stable still + * uses 4.02. *) +let smap_find_opt s m = try Some (SMap.find s m) with Not_found -> None + module IMap = Map.Make (struct type t = int let compare = compare end)
type charpos = int
View it on GitLab: https://gitlab.com/monnier/typer/commit/a7bdf1e671ce956a9780f7f3ca0b01678cee...
Afficher les réponses par date