-(*CSC l'indice x dei tipi induttivi e' t.c. n < x <= nn *)
-(*CSC questa funzione e' simile alla are_all_occurrences_positive, ma fa *)
-(*CSC dei controlli leggermente diversi. Viene invocata solamente dalla *)
-(*CSC strictly_positive *)
-(*CSC definizione (giusta???) tratta dalla mail di Hugo ;-) *)
-let rec weakly_positive ~subst context n nn uri te =
-(*CSC: Che schifo! Bisogna capire meglio e trovare una soluzione ragionevole!*)
- let dummy = C.Sort (C.Type ~-1) in
- (*CSC: mettere in cicSubstitution *)
+let rec eat_lambdas ~subst ~metasenv context n te =
+ match (n, R.whd ~subst context te) with
+ | (0, _) -> (te, context)
+ | (n, C.Lambda (name,so,ta)) when n > 0 ->
+ eat_lambdas ~subst ~metasenv ((name,(C.Decl so))::context) (n - 1) ta
+ | (n, te) ->
+ raise (AssertFailure (lazy (Printf.sprintf "eat_lambdas (%d, %s)" n
+ (PP.ppterm ~subst ~metasenv ~context te))))
+;;
+
+let rec eat_or_subst_lambdas
+ ~subst ~metasenv n te to_be_subst args (context,_,_ as k)
+=
+ match n, R.whd ~subst context te, to_be_subst, args with
+ | (n, C.Lambda (_,_,ta),true::to_be_subst,arg::args) when n > 0 ->
+ eat_or_subst_lambdas ~subst ~metasenv (n - 1) (S.subst arg ta)
+ to_be_subst args k
+ | (n, C.Lambda (name,so,ta),false::to_be_subst,_::args) when n > 0 ->
+ eat_or_subst_lambdas ~subst ~metasenv (n - 1) ta to_be_subst args
+ (shift_k (name,(C.Decl so)) k)
+ | (_, te, _, _) -> te, k
+;;
+
+let check_homogeneous_call ~subst context indparamsno n uri reduct tl =
+ let last =
+ List.fold_left
+ (fun k x ->
+ if k = 0 then 0
+ else
+ match R.whd context x with
+ | C.Rel m when m = n - (indparamsno - k) -> k - 1
+ | _ -> raise (TypeCheckerFailure (lazy
+ ("Argument "^string_of_int (indparamsno - k + 1) ^ " (of " ^
+ string_of_int indparamsno ^ " fixed) is not homogeneous in "^
+ "appl:\n"^ PP.ppterm ~context ~subst ~metasenv:[] reduct))))
+ indparamsno tl
+ in
+ if last <> 0 then
+ raise (TypeCheckerFailure
+ (lazy ("Non-positive occurence in mutual inductive definition(s) [2]"^
+ NUri.string_of_uri uri)))
+;;
+
+(* Inductive types being checked for positivity have *)
+(* indexes x s.t. n < x <= nn. *)
+let rec weakly_positive ~subst context n nn uri indparamsno posuri te =
+ (*CSC: Not very nice. *)
+ let dummy = C.Sort C.Prop in
+ (*CSC: to be moved in cicSubstitution? *)