aboutsummaryrefslogtreecommitdiff
path: root/plugins/extraction/extraction.ml
diff options
context:
space:
mode:
authorppedrot2013-09-27 19:20:27 +0000
committerppedrot2013-09-27 19:20:27 +0000
commit11ca3113365639136cf65a74c345080a9434e69b (patch)
treeda263c149cd1e90bde14768088730e48e78e4776 /plugins/extraction/extraction.ml
parentee2f85396fa0cef65bc4295b5ac6c259e83df134 (diff)
Removing a bunch of generic equalities.
git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/coq/trunk@16806 85f007b7-540e-0410-9357-904b9bb8a0f7
Diffstat (limited to 'plugins/extraction/extraction.ml')
-rw-r--r--plugins/extraction/extraction.ml110
1 files changed, 57 insertions, 53 deletions
diff --git a/plugins/extraction/extraction.ml b/plugins/extraction/extraction.ml
index 6c1be2d364..947a1a482d 100644
--- a/plugins/extraction/extraction.ml
+++ b/plugins/extraction/extraction.ml
@@ -37,13 +37,13 @@ let none = Evd.empty
let type_of env c =
try
- let polyprop = (lang() = Haskell) in
+ let polyprop = (lang() == Haskell) in
Retyping.get_type_of ~polyprop env none (strip_outer_cast c)
with SingletonInductiveBecomesProp id -> error_singleton_become_prop id
let sort_of env c =
try
- let polyprop = (lang() = Haskell) in
+ let polyprop = (lang() == Haskell) in
Retyping.get_sort_family_of ~polyprop env none (strip_outer_cast c)
with SingletonInductiveBecomesProp id -> error_singleton_become_prop id
@@ -78,11 +78,13 @@ let rec flag_of_type env t : flag =
| Prod (x,t,c) -> flag_of_type (push_rel (x,None,t) env) c
| Sort (Prop Null) -> (Logic,TypeScheme)
| Sort _ -> (Info,TypeScheme)
- | _ -> if (sort_of env t) = InProp then (Logic,Default) else (Info,Default)
+ | _ -> if (sort_of env t) == InProp then (Logic,Default) else (Info,Default)
(*s Two particular cases of [flag_of_type]. *)
-let is_default env t = (flag_of_type env t = (Info, Default))
+let is_default env t = match flag_of_type env t with
+| (Info, Default) -> true
+| _ -> false
exception NotDefault of kill_reason
@@ -92,7 +94,9 @@ let check_default env t =
| Logic,_ -> raise (NotDefault Kother)
| _ -> ()
-let is_info_scheme env t = (flag_of_type env t = (Info, TypeScheme))
+let is_info_scheme env t = match flag_of_type env t with
+| (Info, TypeScheme) -> true
+| _ -> false
(*s [type_sign] gernerates a signature aimed at treating a type application. *)
@@ -137,7 +141,7 @@ let sign_with_implicits r s nb_params =
| [] -> []
| sign::s ->
let sign' =
- if sign = Keep && List.mem i implicits then Kill Kother else sign
+ if sign == Keep && List.mem i implicits then Kill Kother else sign
in sign' :: add_impl (succ i) s
in
add_impl (1+nb_params) s
@@ -171,7 +175,7 @@ let db_from_sign s =
an inductive type (see just below). *)
let rec db_from_ind dbmap i =
- if i = 0 then []
+ if Int.equal i 0 then []
else (try Int.Map.find i dbmap with Not_found -> 0)::(db_from_ind dbmap (i-1))
(*s [parse_ind_args] builds a map: [i->j] iff the i-th Coq argument
@@ -195,25 +199,25 @@ let parse_ind_args si args relmax =
in parse 1 1 si
let oib_equal o1 o2 =
- Id.compare o1.mind_typename o2.mind_typename = 0 &&
+ Id.equal o1.mind_typename o2.mind_typename &&
List.equal eq_rel_declaration o1.mind_arity_ctxt o2.mind_arity_ctxt &&
begin match o1.mind_arity, o2.mind_arity with
| Monomorphic {mind_user_arity=c1; mind_sort=s1},
Monomorphic {mind_user_arity=c2; mind_sort=s2} ->
- eq_constr c1 c2 && s1 = s2
- | ma1, ma2 -> ma1 = ma2 end &&
- o1.mind_consnames = o2.mind_consnames
+ eq_constr c1 c2 && Sorts.equal s1 s2
+ | ma1, ma2 -> Pervasives.(=) ma1 ma2 (** FIXME: this one is surely wrong *) end &&
+ Array.equal Id.equal o1.mind_consnames o2.mind_consnames
let mib_equal m1 m2 =
Array.equal oib_equal m1.mind_packets m1.mind_packets &&
- m1.mind_record = m2.mind_record &&
- m1.mind_finite = m2.mind_finite &&
- m1.mind_ntypes = m2.mind_ntypes &&
+ (m1.mind_record : bool) == m2.mind_record &&
+ (m1.mind_finite : bool) == m2.mind_finite &&
+ Int.equal m1.mind_ntypes m2.mind_ntypes &&
List.equal eq_named_declaration m1.mind_hyps m2.mind_hyps &&
- m1.mind_nparams = m2.mind_nparams &&
- m1.mind_nparams_rec = m2.mind_nparams_rec &&
+ Int.equal m1.mind_nparams m2.mind_nparams &&
+ Int.equal m1.mind_nparams_rec m2.mind_nparams_rec &&
List.equal eq_rel_declaration m1.mind_params_ctxt m2.mind_params_ctxt &&
- m1.mind_constraints = m2.mind_constraints
+ Pervasives.(=) m1.mind_constraints m2.mind_constraints (** FIXME *)
(*S Extraction of a type. *)
@@ -236,7 +240,7 @@ let rec extract_type env db j c args =
| [] -> assert false (* A lambda cannot be a type. *)
| a :: args -> extract_type env db j (subst1 a d) args)
| Prod (n,t,d) ->
- assert (args = []);
+ assert (List.is_empty args);
let env' = push_rel_assum (n,t) env in
(match flag_of_type env t with
| (Info, Default) ->
@@ -256,10 +260,10 @@ let rec extract_type env db j c args =
(match expand env mld with
| Tdummy d -> Tdummy d
| _ ->
- let reason = if lvl=TypeScheme then Ktype else Kother in
+ let reason = if lvl == TypeScheme then Ktype else Kother in
Tarr (Tdummy reason, mld)))
| Sort _ -> Tdummy Ktype (* The two logical cases. *)
- | _ when sort_of env (applist (c, args)) = InProp -> Tdummy Kother
+ | _ when sort_of env (applist (c, args)) == InProp -> Tdummy Kother
| Rel n ->
(match lookup_rel n env with
| (_,Some t,_) -> extract_type env db j (lift n t) args
@@ -267,7 +271,7 @@ let rec extract_type env db j c args =
(* Asks [db] a translation for [n]. *)
if n > List.length db then Tunknown
else let n' = List.nth db (n-1) in
- if n' = 0 then Tunknown else Tvar n')
+ if Int.equal n' 0 then Tunknown else Tvar n')
| Const kn ->
let r = ConstRef kn in
let cb = lookup_constant kn env in
@@ -287,7 +291,7 @@ let rec extract_type env db j c args =
(* The more precise is [mlt'], extracted after reduction *)
(* The shortest is [mlt], which use abbreviations *)
(* If possible, we take [mlt], otherwise [mlt']. *)
- if expand env mlt = expand env mlt' then mlt else mlt')
+ if Pervasives.(=) (expand env mlt) (expand env mlt') then mlt else mlt') (** FIXME *)
| (Info, Default) ->
(* Not an ML type, for example [(c:forall X, X->X) Type nat] *)
(match cb.const_body with
@@ -309,7 +313,7 @@ let rec extract_type env db j c args =
and extract_type_app env db (r,s) args =
let ml_args =
List.fold_right
- (fun (b,c) a -> if b=Keep then
+ (fun (b,c) a -> if b == Keep then
let p = List.length (fst (splay_prod env none (type_of env c))) in
let db = iterate (fun l -> 0 :: l) p db in
(extract_type_scheme env db c p) :: a
@@ -327,7 +331,7 @@ and extract_type_app env db (r,s) args =
(* [db] is a context for translating Coq [Rel] into ML type [Tvar]. *)
and extract_type_scheme env db c p =
- if p=0 then extract_type env db 0 c []
+ if Int.equal p 0 then extract_type env db 0 c []
else
let c = whd_betaiotazeta Evd.empty c in
match kind_of_term c with
@@ -357,9 +361,9 @@ and extract_ind env kn = (* kn is supposed to be in long form *)
When at toplevel of the monolithic case, we cannot do much
(cf Vector and bug #2570) *)
let equiv =
- if lang () <> Ocaml ||
+ if lang () != Ocaml ||
(not (modular ()) && at_toplevel (mind_modpath kn)) ||
- kn_ord (canonical_mind kn) (user_mind kn) = 0
+ KerName.equal (canonical_mind kn) (user_mind kn)
then
NoEquiv
else
@@ -379,7 +383,7 @@ and extract_ind env kn = (* kn is supposed to be in long form *)
Array.mapi
(fun i mip ->
let ar = Inductive.type_of_inductive env (mib,mip) in
- let info = (fst (flag_of_type env ar) = Info) in
+ let info = (fst (flag_of_type env ar) == Info) in
let s,v = if info then type_sign_vl env ar else [],[] in
let t = Array.make (Array.length mip.mind_nf_lc) [] in
{ ip_typename = mip.mind_typename;
@@ -422,16 +426,16 @@ and extract_ind env kn = (* kn is supposed to be in long form *)
let r = IndRef ip in
if is_custom r then raise (I Standard);
if not mib.mind_finite then raise (I Coinductive);
- if mib.mind_ntypes <> 1 then raise (I Standard);
+ if not (Int.equal mib.mind_ntypes 1) then raise (I Standard);
let p = packets.(0) in
if p.ip_logical then raise (I Standard);
- if Array.length p.ip_types <> 1 then raise (I Standard);
+ if not (Int.equal (Array.length p.ip_types) 1) then raise (I Standard);
let typ = p.ip_types.(0) in
let l = List.filter (fun t -> not (isDummy (expand env t))) typ in
if not (keep_singleton ()) &&
- List.length l = 1 && not (type_mem_kn kn (List.hd l))
+ Int.equal (List.length l) 1 && not (type_mem_kn kn (List.hd l))
then raise (I Singleton);
- if l = [] then raise (I Standard);
+ if List.is_empty l then raise (I Standard);
if not mib.mind_record then raise (I Standard);
(* Now we're sure it's a record. *)
(* First, we find its field names. *)
@@ -443,7 +447,7 @@ and extract_ind env kn = (* kn is supposed to be in long form *)
in
let field_names =
List.skipn mib.mind_nparams (names_prod mip0.mind_user_lc.(0)) in
- assert (List.length field_names = List.length typ);
+ assert (Int.equal (List.length field_names) (List.length typ));
let projs = ref Cset.empty in
let mp = MutInd.modpath kn in
let rec select_fields l typs = match l,typs with
@@ -455,7 +459,7 @@ and extract_ind env kn = (* kn is supposed to be in long form *)
| Name id::l, typ::typs ->
let knp = Constant.make2 mp (Label.of_id id) in
(* Is it safe to use [id] for projections [foo.id] ? *)
- if List.for_all ((=) Keep) (type2signature env typ)
+ if List.for_all ((==) Keep) (type2signature env typ)
then projs := Cset.add knp !projs;
Some (ConstRef knp) :: (select_fields l typs)
| _ -> assert false
@@ -653,7 +657,7 @@ and extract_cst_app env mle mlt kn args =
(* Can we instantiate types variables for this constant ? *)
(* In Ocaml, inside the definition of this constant, the answer is no. *)
let instantiated =
- if lang () = Ocaml && List.mem kn !current_fixpoints then var2var' (snd schema)
+ if lang () == Ocaml && List.mem kn !current_fixpoints then var2var' (snd schema)
else instantiation schema
in
(* Then the expected type of this constant. *)
@@ -675,14 +679,14 @@ and extract_cst_app env mle mlt kn args =
(* The ml arguments, already expunged from known logical ones *)
let mla = make_mlargs env mle s args metas in
let mla =
- if magic1 || lang () <> Ocaml then mla
+ if magic1 || lang () != Ocaml then mla
else
try
(* for better optimisations later, we discard dependent args
of projections and replace them by fake args that will be
removed during final pretty-print. *)
let l,l' = List.chop (projection_arity (ConstRef kn)) mla in
- if l' <> [] then (List.map (fun _ -> MLexn "Proj Args") l) @ l'
+ if not (List.is_empty l') then (List.map (fun _ -> MLexn "Proj Args") l) @ l'
else mla
with e when Errors.noncritical e -> mla
in
@@ -690,7 +694,7 @@ and extract_cst_app env mle mlt kn args =
one [Kill Kother] lead to a dummy lam. So a [MLdummy] is left
accordingly. *)
let optdummy = match sign_kind s_full with
- | UnsafeLogicalSig when lang () <> Haskell -> [MLdummy]
+ | UnsafeLogicalSig when lang () != Haskell -> [MLdummy]
| _ -> []
in
(* Different situations depending of the number of arguments: *)
@@ -743,7 +747,7 @@ and extract_cons_app env mle mlt (((kn,i) as ip,j) as cp) args =
let magic1 = needs_magic (type_cons, type_recomp (metas, a)) in
let magic2 = needs_magic (a, mlt) in
let head mla =
- if mi.ind_kind = Singleton then
+ if mi.ind_kind == Singleton then
put_magic_if magic1 (List.hd mla) (* assert (List.length mla = 1) *)
else
let typeargs = match snd (type_decomp type_cons) with
@@ -760,7 +764,7 @@ and extract_cons_app env mle mlt (((kn,i) as ip,j) as cp) args =
(dummy_lams (anonym_or_dummy_lams head' s) (params_nb - la))
else
let mla = make_mlargs env mle s args' metas in
- if la = ls + params_nb
+ if Int.equal la (ls + params_nb)
then put_magic_if (magic2 && not magic1) (head mla)
else (* [ params_nb <= la <= ls + params_nb ] *)
let ls' = params_nb + ls - la in
@@ -775,20 +779,20 @@ and extract_case env mle ((kn,i) as ip,c,br) mlt =
(* [ni]: number of arguments without parameters in each branch *)
let ni = mis_constr_nargs_env env ip in
let br_size = Array.length br in
- assert (Array.length ni = br_size);
- if br_size = 0 then begin
+ assert (Int.equal (Array.length ni) br_size);
+ if Int.equal br_size 0 then begin
add_recursors env kn; (* May have passed unseen if logical ... *)
MLexn "absurd case"
end else
(* [c] has an inductive type, and is not a type scheme type. *)
let t = type_of env c in
(* The only non-informative case: [c] is of sort [Prop] *)
- if (sort_of env t) = InProp then
+ if (sort_of env t) == InProp then
begin
add_recursors env kn; (* May have passed unseen if logical ... *)
(* Logical singleton case: *)
(* [match c with C i j k -> t] becomes [t'] *)
- assert (br_size = 1);
+ assert (Int.equal br_size 1);
let s = iterate (fun l -> Kill Kother :: l) ni.(0) [] in
let mlt = iterate (fun t -> Tarr (Tdummy Kother, t)) ni.(0) mlt in
let e = extract_maybe_term env mle mlt br.(0) in
@@ -817,13 +821,13 @@ and extract_case env mle ((kn,i) as ip,c,br) mlt =
let e' = handle_exn r (List.length s) (fun _ -> Anonymous) e in
(List.rev ids, Pusual r, e')
in
- if mi.ind_kind = Singleton then
+ if mi.ind_kind == Singleton then
begin
(* Informative singleton case: *)
(* [match c with C i -> t] becomes [let i = c' in t'] *)
- assert (br_size = 1);
+ assert (Int.equal br_size 1);
let (ids,_,e') = extract_branch 0 in
- assert (List.length ids = 1);
+ assert (Int.equal (List.length ids) 1);
MLletin (tmp_id (List.hd ids),a,e')
end
else
@@ -893,8 +897,8 @@ let extract_std_constant env kn body typ =
if n <= m then decompose_lam_n n body
else
let s,s' = List.chop m s in
- if List.for_all ((=) Keep) s' &&
- (lang () = Haskell || sign_kind s <> UnsafeLogicalSig)
+ if List.for_all ((==) Keep) s' &&
+ (lang () == Haskell || sign_kind s != UnsafeLogicalSig)
then decompose_lam_n m body
else decomp_lams_eta_n n m env body typ
in
@@ -903,9 +907,9 @@ let extract_std_constant env kn body typ =
let n = List.length rels in
let s,s' = List.chop n s in
let k = sign_kind s in
- let empty_s = (k = EmptySig || k = SafeLogicalSig) in
- if lang () = Ocaml && empty_s && not (gentypvar_ok c)
- && s' <> [] && type_maxvar t <> 0
+ let empty_s = (k == EmptySig || k == SafeLogicalSig) in
+ if lang () == Ocaml && empty_s && not (gentypvar_ok c)
+ && not (List.is_empty s') && not (Int.equal (type_maxvar t) 0)
then decomp_lams_eta_n (n+1) n env body typ
else rels,c
in
@@ -949,7 +953,7 @@ let extract_fixpoint env vkn (fi,ti,ci) =
(* for replacing recursive calls [Rel ..] by the corresponding [Const]: *)
let sub = List.rev_map mkConst kns in
for i = 0 to n-1 do
- if sort_of env ti.(i) <> InProp then begin
+ if sort_of env ti.(i) != InProp then begin
let e,t = extract_std_constant env vkn.(i) (substl sub ci.(i)) ti.(i) in
terms.(i) <- e;
types.(i) <- t;
@@ -1059,7 +1063,7 @@ let logical_decl = function
| Dterm (_,MLdummy,Tdummy _) -> true
| Dtype (_,[],Tdummy _) -> true
| Dfix (_,av,tv) ->
- (Array.for_all ((=) MLdummy) av) &&
+ (Array.for_all ((==) MLdummy) av) &&
(Array.for_all isDummy tv)
| Dind (_,i) -> Array.for_all (fun ip -> ip.ip_logical) i.ind_packets
| _ -> false