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_______________________________________________________________ *)
15 module Ref = NReference
17 exception Subst_not_found of int
18 exception Meta_not_found of int
20 let expand_local_context = function
22 let rec aux acc = function
24 | n -> aux (C.Rel n::acc) (n-1)
30 let lookup_subst n subst =
33 with Not_found -> raise (Subst_not_found n)
36 let lookup_meta n metasenv =
39 with Not_found -> raise (Meta_not_found n)
42 let fold g k f acc = function
43 | C.Meta _ -> assert false
48 | C.Appl [] | C.Appl [_] -> assert false
49 | C.Appl l -> List.fold_left (f k) acc l
51 | C.Lambda (n,s,t) -> f (g (n,C.Decl s) k) (f k acc s) t
52 | C.LetIn (n,ty,t,bo) -> f (g (n,C.Def (t,ty)) k) (f k (f k acc ty) t) bo
53 | C.Match (_,oty,t,pl) -> List.fold_left (f k) (f k (f k acc oty) t) pl
56 let map g k f = function
57 | C.Meta _ -> assert false
62 | C.Appl [] | C.Appl [_] -> assert false
64 (match HExtlib.sharing_map (f k) l with
65 | C.Appl l :: tl -> C.Appl (l@tl)
66 | l1 when l == l1 -> orig
68 | C.Prod (n,s,t) as orig ->
69 let s1 = f k s in let t1 = f (g (n,C.Decl s) k) t in
70 if t1 == t && s1 == s then orig else C.Prod (n,s1,t1)
71 | C.Lambda (n,s,t) as orig ->
72 let s1 = f k s in let t1 = f (g (n,C.Decl s) k) t in
73 if t1 == t && s1 == s then orig else C.Lambda (n,s1,t1)
74 | C.LetIn (n,ty,t,b) as orig ->
75 let ty1 = f k ty in let t1 = f k t in
76 let b1 = f (g (n,C.Def (t,ty)) k) b in
77 if ty1 == ty && t1 == t && b1 == b then orig else C.LetIn (n,ty1,t1,b1)
78 | C.Match (r,oty,t,pl) as orig ->
79 let oty1 = f k oty in let t1 = f k t in let pl1 = HExtlib.sharing_map (f k) pl in
80 if oty1 == oty && t1 == t && pl1 == pl then orig
81 else C.Match(r,oty1,t1,pl1)