+let find_hyp name =
+ let rec find_hyp n =
+ function
+ [] -> assert false
+ | Some (Cic.Name s,Cic.Decl ty)::_ when name = s ->
+ Cic.Rel n, CicSubstitution.lift n ty
+ | Some (Cic.Name s,Cic.Def _)::_ when name = s -> assert false (*CSC: not implemented yet! But does this make any sense?*)
+ | _::tl -> find_hyp (n+1) tl
+ in
+ find_hyp 1
+;;
+
+(* sort pattern hypotheses from the smallest to the highest Rel *)
+let sort_pattern_hyps context (t,hpatterns,cpattern) =
+ let hpatterns =
+ List.sort
+ (fun (id1,_) (id2,_) ->
+ let t1,_ = find_hyp id1 context in
+ let t2,_ = find_hyp id2 context in
+ match t1,t2 with
+ Cic.Rel n1, Cic.Rel n2 -> compare n1 n2
+ | _,_ -> assert false) hpatterns
+ in
+ t,hpatterns,cpattern
+;;
+