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_______________________________________________________________ *)
19 (* internal functions: crg to bag term **************************************)
21 let rec shift t = function
23 | (a, l, b) :: c, _ :: ns -> shift (Z.Bind (a, l, b, t)) (c, ns)
26 let rec xlate_term xlate_bind f c = function
27 | D.TSort (_, h) -> f (Z.Sort h)
28 | D.TGRef (_, s) -> f (Z.GRef s)
29 | D.TLRef (a, _, _) ->
31 let _, l, _ = List.nth c i in
35 | D.TCast (_, u, t) ->
36 let f tt uu = f (Z.Cast (uu, tt)) in
37 let f tt = xlate_term xlate_bind (f tt) c u in
38 xlate_term xlate_bind f c t
39 | D.TAppl (_, vs, t) ->
40 let map f v tt = let f vv = f (Z.Appl (vv, tt)) in xlate_term xlate_bind f c v in
41 let f tt = C.list_fold_right f map vs tt in
42 xlate_term xlate_bind f c t
43 | D.TProj (_, e, t) ->
44 xlate_term xlate_bind f c (D.tshift e t)
45 | D.TBind (ab, D.Abst (n, ws), D.TCast (ac, u, t)) ->
46 xlate_term xlate_bind f c (D.TCast (ac, D.TBind (ab, D.Abst (N.pred n, ws), u), D.TBind (ab, D.Abst (n, ws), t)))
47 | D.TBind (a, b, t) ->
49 let ns = E.get_names g a in
50 let cc = xlate_bind C.start c ns b in
51 let f tt = f (shift tt (cc, ns)) in
52 xlate_term xlate_bind f cc t
54 let rec xlate_bind f c ns = function
57 let f ww = Z.push "xlate_bind" f c [n] (J.new_location ()) (Z.Abst ww) in
58 xlate_term xlate_bind f c w
60 C.list_fold_right2 f map ns ws c
63 let f vv = Z.push "xlate_bind" f c [n] (J.new_location ()) (Z.Abbr vv) in
64 xlate_term xlate_bind f c v
66 C.list_fold_right2 f map ns vs c
68 let map f n c = Z.push "xlate_bind" f c [n] (J.new_location ()) Z.Void in
69 C.list_fold_right f map ns c
71 (* internal functions: bag to crg term **************************************)
73 let rec xlate_bk_term f c = function
74 | Z.Sort h -> f (D.TSort ([], h))
75 | Z.GRef s -> f (D.TGRef ([], s))
77 let f i = f (D.TLRef ([], i, 0)) in
80 let f tt uu = f (D.TCast ([], uu, tt)) in
81 let f tt = xlate_bk_term (f tt) c u in
84 let f tt uu = f (D.TAppl ([], [uu], tt)) in
85 let f tt = xlate_bk_term (f tt) c u in
87 | Z.Bind (a, l, b, t) ->
88 let f tt bb = f (D.TBind (a, bb, tt)) in
89 let f tt = xlate_bk_bind (f tt) c b in
90 let cc = Z.push "xlate_bk_term" C.start c a l b in
93 and xlate_bk_bind f c = function
95 let f tt = f (D.Abst (N.infinite, [tt])) in
98 let f tt = f (D.Abbr [tt]) in
100 | Z.Void -> f (D.Void 1)
102 (* interface functions ******************************************************)
105 xlate_term xlate_bind f Z.empty_lenv t
107 let crg_of_bag f t = xlate_bk_term f Z.empty_lenv t