]> matita.cs.unibo.it Git - helm.git/blob - helm/software/helena/src/common/entity.ml
- bug fix in the static analyzer allows better Pi/forall separation (exportation...
[helm.git] / helm / software / helena / src / common / entity.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 U = NUri
13 module N = Layer
14
15 type uri = U.uri
16
17 type id = string (* identifier *)
18
19 type name = id * bool (* token, real? *)
20
21 type arity = int * int (* sort, degree *)
22
23 type meta = Main     (* main object *)
24           | InProp   (* inhabitant of a proposition *)
25           | Progress (* uncompleted object *)
26           | Private  (* private global definition *)
27
28 type node_attrs = {
29    n_name: name option; (* name *)
30    n_apix: int;         (* additional position index *)
31    n_main: arity;       (* main arity *)
32    n_side: arity;       (* side arity *)
33 }
34
35 type root_attrs = {
36    r_meta: meta list;                (* metaliguistic classification *) 
37    r_info: (string * string) option; (* metaliguistic annotation: language (defaults to "en-US"), text *)
38 }
39
40 type 'term bind = Abst of 'term (* declaration: domain *)
41                 | Abbr of 'term (* definition: body    *)
42                 | Void          (* exclusion           *)
43
44 type 'term entity = root_attrs * node_attrs * uri * 'term bind (* attrs, uri, binder *)
45
46 (* helpers ******************************************************************)
47
48 let node_attrs ?name ?(main=(0,0)) ?(side=(0,0)) () = {
49    n_apix = 0; n_name = name; n_main = main; n_side = side;
50 }
51
52 let root_attrs ?(meta=[]) ?info () = {
53    r_meta = meta; r_info = info;
54 }
55
56 let empty_node = node_attrs ()
57
58 let empty_root = root_attrs ()
59
60 let common f (ra, na, u, _) = f ra na u
61
62 let succ (sort, degr) = sort, succ degr
63
64 let compose av at = {av with n_main = at.n_main}
65
66 let shift av = {av with n_side = av.n_main}
67
68 let rec name err f a = match a.n_name with
69    | Some (n, r) -> f n r
70    | None        -> err ()
71
72 let rec info err f a = match a.r_info with
73    | Some (lg, tx) -> f lg tx
74    | None          -> err ()
75
76 let xlate f xlate_term = function
77    | ra, na, uri, Abst t ->
78       let f t = f (ra, na, uri, Abst t) in xlate_term f t
79    | ra, na, uri, Abbr t ->
80       let f t = f (ra, na, uri, Abbr t) in xlate_term f t
81    | _, _, _, Void       ->
82       assert false