]> matita.cs.unibo.it Git - helm.git/blob - helm/software/lambda-delta/toplevel/metaBrg.ml
new kernel basic_rg: implements ufficial lambda-delta with de Bruijn indexes
[helm.git] / helm / software / lambda-delta / toplevel / metaBrg.ml
1 (*
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.                     
5     ||I||                                                                
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_______________________________________________________________ *)
11
12 module C = Cps
13 module B = Brg
14 module M = Meta
15
16 (* Internal functions *******************************************************)
17
18 let rec xlate_term c f = function
19    | M.Sort s            -> 
20       let f h = f (B.Sort ([], h)) in
21       if s then f 0 else f 1
22    | M.LRef (_, i)       ->
23       f (B.LRef ([], i))
24    | M.GRef (_, uri, vs) ->
25       let map f t v = f (B.appl [] v t) in
26       let f vs = C.list_fold_left f map (B.GRef ([], uri)) vs in
27       C.list_map f (xlate_term c) vs
28    | M.Appl (v, t)       ->
29       let f v t = f (B.Appl ([], v, t)) in
30       let f v = xlate_term c (f v) t in
31       xlate_term c f v
32    | M.Abst (id, w, t)   ->
33       let f w = 
34          let a = [B.Name (true, id)] in
35          let f t = f (B.Bind (a, B.Abst w, t)) in
36          let f c = xlate_term c f t in
37          B.push f c a (B.Abst w)
38       in
39       xlate_term c f w
40
41 let xlate_pars f pars =
42    let map f (id, w) c =
43       let a = [B.Name (true, id)] in
44       let f w = B.push f c a (B.Abst w) in
45       xlate_term c f w
46    in
47    C.list_fold_right f map pars B.empty_context
48
49 let unwind_to_xlate_term f c t =
50    let map f t (a, b) = f (B.bind a b t) in
51    let f t = C.list_fold_left f map t c in
52    xlate_term c f t
53
54 let xlate_entry f = function
55    | e, pars, uri, u, None        ->
56       let f u = f (e, uri, B.Abst u) in
57       let f c = unwind_to_xlate_term f c u in      
58       xlate_pars f pars   
59    | e, pars, uri, u, Some (_, t) ->
60       let f u t = f (e, uri, B.Abbr (B.Cast ([], u, t))) in
61       let f c u = unwind_to_xlate_term (f u) c t in
62       let f c = unwind_to_xlate_term (f c) c u in
63       xlate_pars f pars
64
65 let xlate_item f = function
66    | None   -> f None
67    | Some e -> let f e = f (Some e) in xlate_entry f e
68
69 (* Interface functions ******************************************************)
70
71 let brg_of_meta = xlate_item