2 ||M|| This file is part of HELM, an Hypertextual, Electronic
3 ||A|| Library of Mathematics, developed at the Computer Science
4 ||T|| Department, University of Bologna, Italy.
6 ||T|| HELM is free software; you can redistribute it and/or
7 ||A|| modify it under the terms of the GNU General Public License
8 \ / version 2 or (at your option) any later version.
9 \ / This software is distributed as is, NO WARRANTY.
10 V_______________________________________________________________ *)
14 exception Subst_not_found of int
15 exception Meta_not_found of int
17 let expand_local_context = function
19 let rec aux acc = function
21 | n -> aux (NCic.Rel n::acc) (n-1)
24 | NCic.Ctx lctx -> lctx
27 let lookup_subst n subst =
30 with Not_found -> raise (Subst_not_found n)
33 let lookup_meta n metasenv =
36 with Not_found -> raise (Meta_not_found n)
39 let fold g k f acc = function
40 | NCic.Meta _ -> assert false
45 | NCic.Appl [] | NCic.Appl [_] -> assert false
46 | NCic.Appl l -> List.fold_left (f k) acc l
48 | NCic.Lambda (n,s,t) -> f (g (n,NCic.Decl s) k) (f k acc s) t
49 | NCic.LetIn (n,ty,t,bo) -> f (g (n,NCic.Def (t,ty)) k) (f k (f k acc ty) t) bo
50 | NCic.Match (_,oty,t,pl) -> List.fold_left (f k) (f k (f k acc oty) t) pl
53 let map g k f = function
54 | NCic.Meta _ -> assert false
58 | NCic.Rel _ as t -> t
59 | NCic.Appl [] | NCic.Appl [_] -> assert false
60 | NCic.Appl l as orig ->
61 (match HExtlib.sharing_map (f k) l with
62 | NCic.Appl l :: tl -> NCic.Appl (l@tl)
63 | l1 when l == l1 -> orig
65 | NCic.Prod (n,s,t) as orig ->
66 let s1 = f k s in let t1 = f (g (n,NCic.Decl s) k) t in
67 if t1 == t && s1 == s then orig else NCic.Prod (n,s1,t1)
68 | NCic.Lambda (n,s,t) as orig ->
69 let s1 = f k s in let t1 = f (g (n,NCic.Decl s) k) t in
70 if t1 == t && s1 == s then orig else NCic.Lambda (n,s1,t1)
71 | NCic.LetIn (n,ty,t,b) as orig ->
72 let ty1 = f k ty in let t1 = f k t in
73 let b1 = f (g (n,NCic.Def (t,ty)) k) b in
74 if ty1 == ty && t1 == t && b1 == b then orig else NCic.LetIn (n,ty1,t1,b1)
75 | NCic.Match (r,oty,t,pl) as orig ->
76 let oty1 = f k oty in let t1 = f k t in let pl1 = HExtlib.sharing_map (f k) pl in
77 if oty1 == oty && t1 == t && pl1 == pl then orig
78 else NCic.Match(r,oty1,t1,pl1)