let source_id_of_id id = "#source#" ^ id;;
-exception NotEnoughElements;;
+exception NotEnoughElements of string;;
(*CSC: cut&paste da cicPp.ml *)
(* get_nth l n returns the nth element of the list l if it exists or *)
(* raises NotEnoughElements if l has less than n elements *)
-let rec get_nth l n =
+let rec get_nth msg l n =
match (n,l) with
(1, he::_) -> he
- | (n, he::tail) when n > 1 -> get_nth tail (n-1)
- | (_,_) -> raise NotEnoughElements
+ | (n, he::tail) when n > 1 -> get_nth msg tail (n-1)
+ | (_,_) -> raise (NotEnoughElements msg)
;;
match tt with
C.Rel n ->
let id =
- match get_nth context n with
+ match get_nth "1" context n with
(Some (C.Name s,_)) -> s
| _ -> "__" ^ string_of_int n
in
let fresh_idrefs =
List.map (function _ -> gen_id seed) funs in
let new_idrefs = List.rev fresh_idrefs @ idrefs in
- let tys =
- List.map (fun (name,_,ty,_) -> Some (C.Name name, C.Decl ty)) funs
+ let tys,_ =
+ List.fold_left
+ (fun (types,len) (n,_,ty,_) ->
+ (Some (C.Name n,(C.Decl (CicSubstitution.lift len ty)))::types,
+ len+1)
+ ) ([],0) funs
in
xxx_add ids_to_inner_sorts fresh_id'' innersort ;
if innersort = `Prop then
let fresh_idrefs =
List.map (function _ -> gen_id seed) funs in
let new_idrefs = List.rev fresh_idrefs @ idrefs in
- let tys =
- List.map (fun (name,ty,_) -> Some (C.Name name, C.Decl ty)) funs
+ let tys,_ =
+ List.fold_left
+ (fun (types,len) (n,ty,_) ->
+ (Some (C.Name n,(C.Decl (CicSubstitution.lift len ty)))::types,
+ len+1)
+ ) ([],0) funs
in
xxx_add ids_to_inner_sorts fresh_id'' innersort ;
if innersort = `Prop then
match t with
C.Rel n ->
let idref,id =
- match get_nth context n with
+ match get_nth "2" context n with
idref,(Some (C.Name s,_)) -> idref,s
| idref,_ -> idref,"__" ^ string_of_int n
in
C.AMutCase (fresh_id, uri, tyno, aux context outty,
aux context term, List.map (aux context) patterns)
| C.Fix (funno, funs) ->
- let tys =
- List.map
- (fun (name,_,ty,_) -> mk_fresh_id (), Some (C.Name name, C.Decl ty)) funs
+ let tys,_ =
+ List.fold_left
+ (fun (types,len) (n,_,ty,_) ->
+ (mk_fresh_id (),(Some (C.Name n,(C.Decl (CicSubstitution.lift len ty)))))::types,
+ len+1
+ ) ([],0) funs
in
C.AFix (fresh_id, funno,
List.map2
) tys funs
)
| C.CoFix (funno, funs) ->
- let tys =
- List.map (fun (name,ty,_) ->
- mk_fresh_id (),Some (C.Name name, C.Decl ty)) funs
+ let tys,_ =
+ List.fold_left
+ (fun (types,len) (n,ty,_) ->
+ (mk_fresh_id (),(Some (C.Name n,(C.Decl (CicSubstitution.lift len ty)))))::types,
+ len+1
+ ) ([],0) funs
in
C.ACoFix (fresh_id, funno,
List.map2