]> matita.cs.unibo.it Git - helm.git/blob - helm/software/components/cic/cic_indexable.ml
Preparing for 0.5.9 release.
[helm.git] / helm / software / components / cic / cic_indexable.ml
1 (* Copyright (C) 2005, HELM Team.
2  * 
3  * This file is part of HELM, an Hypertextual, Electronic
4  * Library of Mathematics, developed at the Computer Science
5  * Department, University of Bologna, Italy.
6  * 
7  * HELM is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  * 
12  * HELM is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with HELM; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place - Suite 330, Boston,
20  * MA  02111-1307, USA.
21  * 
22  * For details, see the HELM World-Wide-Web page,
23  * http://cs.unibo.it/helm/.
24  *)
25
26 (* $Id: discrimination_tree.ml 8991 2008-09-19 12:47:23Z tassi $ *)
27
28 module CicIndexable : Discrimination_tree.Indexable 
29 with type input = Cic.term and type constant_name = UriManager.uri 
30 = struct
31
32         type input = Cic.term
33         type constant_name = UriManager.uri
34         open Discrimination_tree
35         
36         let ppelem = function
37           | Constant (uri,arity) -> 
38               "("^UriManager.name_of_uri uri ^ "," ^ string_of_int arity^")"
39           | Bound (i,arity) -> 
40               "("^string_of_int i ^ "," ^ string_of_int arity^")"
41           | Variable -> "?"
42           | Proposition -> "Prop"
43           | Datatype -> "Type"
44           | Dead -> "Dead"
45         ;;
46
47         let path_string_of =
48           let rec aux arity = function
49             | Cic.Appl ((Cic.Meta _|Cic.Implicit _)::_) -> [Variable]
50             | Cic.Appl (Cic.Lambda _ :: _) -> 
51                 [Variable] (* maybe we should b-reduce *)
52             | Cic.Appl [] -> assert false
53             | Cic.Appl (hd::tl) ->
54                 aux (List.length tl) hd @ List.flatten (List.map (aux 0) tl) 
55             | Cic.Cast (t,_) -> aux arity t
56             | Cic.Lambda (_,s,t) | Cic.Prod (_,s,t) -> [Variable]
57                 (* I think we should CicSubstitution.subst Implicit t *)
58             | Cic.LetIn (_,s,_,t) -> [Variable] (* z-reduce? *)
59             | Cic.Meta _ | Cic.Implicit _ -> assert (arity = 0); [Variable]
60             | Cic.Rel i -> [Bound (i, arity)]
61             | Cic.Sort (Cic.Prop) -> assert (arity=0); [Proposition]
62             | Cic.Sort _ -> assert (arity=0); [Datatype]
63             | Cic.Const _ | Cic.Var _ 
64             | Cic.MutInd _ | Cic.MutConstruct _ as t ->
65                 [Constant (CicUtil.uri_of_term t, arity)]
66             | Cic.MutCase _ | Cic.Fix _ | Cic.CoFix _ -> [Dead]
67           in 
68             aux 0
69         ;;
70
71         let compare e1 e2 =
72           match e1,e2 with
73           | Constant (u1,a1),Constant (u2,a2) -> 
74                let x = UriManager.compare u1 u2 in
75                if x = 0 then Pervasives.compare a1 a2 else x
76           | e1,e2 -> Pervasives.compare e1 e2
77         ;;
78         
79         let string_of_path l = String.concat "." (List.map ppelem l) ;;
80 end 
81