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_______________________________________________________________ *)
18 (* internal functions: crg to brg term **************************************)
20 let rec lenv_fold_left map1 map2 x = function
22 | D.EBind (tl, a, b) -> lenv_fold_left map1 map2 (map1 x a b) tl
23 | D.EProj (tl, a, e) -> lenv_fold_left map1 map2 (map2 x a e) tl
25 let rec xlate_term f = function
26 | D.TSort (a, l) -> f (B.Sort (a, l))
27 | D.TGRef (a, n) -> f (B.GRef (a, n))
28 | D.TLRef (a, _, _) -> let f i = f (B.LRef (a, i)) in Y.apix C.err f a
29 | D.TCast (a, u, t) ->
30 let f uu tt = f (B.Cast (a, uu, tt)) in
31 let f uu = xlate_term (f uu) t in
33 | D.TAppl (a, vs, t) ->
34 let map f v tt = let f vv = f (B.Appl (a, vv, tt)) in xlate_term f v in
35 let f tt = C.list_fold_right f map vs tt in
37 | D.TProj (a, e, t) ->
38 let f tt = f (lenv_fold_left xlate_bind xlate_proj tt e) in
40 | D.TBind (ab, D.Abst ws, D.TCast (ac, u, t)) ->
41 xlate_term f (D.TCast (ac, D.TBind (ab, D.Abst ws, u), D.TBind (ab, D.Abst ws, t)))
42 | D.TBind (a, b, t) ->
43 let f tt = f (xlate_bind tt a b) in xlate_term f t
45 and xlate_bind x a b =
47 let a, ns = Y.get_names f a in
51 let f ww = B.Bind (n :: M.new_mark () :: a, B.Abst ww, x) in
54 List.fold_left2 map x ns ws
57 let f vv = B.Bind (n :: a, B.Abbr vv, x) in
60 List.fold_left2 map x ns vs
62 let map x n = B.Bind (n :: a, B.Void, x) in
63 List.fold_left map x ns
65 and xlate_proj x _ e =
66 lenv_fold_left xlate_bind xlate_proj x e
68 (* internal functions: brg to crg term **************************************)
70 let rec xlate_bk_term f = function
71 | B.Sort (a, l) -> f (D.TSort (a, l))
72 | B.GRef (a, n) -> f (D.TGRef (a, n))
73 | B.LRef (a, i) -> f (D.TLRef (a, i, 0))
75 let f uu tt = f (D.TCast (a, uu, tt)) in
76 let f uu = xlate_bk_term (f uu) t in
79 let f uu tt = f (D.TAppl (a, [uu], tt)) in
80 let f uu = xlate_bk_term (f uu) t in
83 let f bb tt = f (D.TBind (a, bb, tt)) in
84 let f bb = xlate_bk_term (f bb) t in
87 and xlate_bk_bind f = function
89 let f tt = f (D.Abst [tt]) in
92 let f tt = f (D.Abbr [tt]) in
94 | B.Void -> f (D.Void 1)
96 (* interface functions ******************************************************)
99 f (xlate_term C.start t)
101 let crg_of_brg = xlate_bk_term