]> matita.cs.unibo.it Git - helm.git/blob - helm/software/components/ng_refiner/nDiscriminationTree.ml
snapshot
[helm.git] / helm / software / components / ng_refiner / nDiscriminationTree.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$ *)
27 (*
28 module NCicIndexable : Discrimination_tree.Indexable
29 with type input = NCic.term and type constant_name = NUri.uri = struct
30
31 let ppelem = function
32   | Constant (uri,arity) -> 
33       "("^NUri.name_of_uri uri ^ "," ^ string_of_int arity^")"
34   | Bound (i,arity) -> 
35       "("^string_of_int i ^ "," ^ string_of_int arity^")"
36   | Variable -> "?"
37   | Proposition -> "Prop"
38   | Datatype -> "Type"
39   | Dead -> "Dead"
40 ;;
41
42 let path_string_of =
43   let rec aux arity = function
44     | NCic.Appl ((NCic.Meta _|NCic.Implicit _)::_) -> [Variable]
45     | NCic.Appl (NCic.Lambda _ :: _) -> [Variable] (* maybe we should b-reduce *)
46     | NCic.Appl [] -> assert false
47     | NCic.Appl (hd::tl) ->
48         aux (List.length tl) hd @ List.flatten (List.map (aux 0) tl) 
49     | NCic.Lambda _ | NCic.Prod _ -> [Variable]
50         (* I think we should CicSubstitution.subst Implicit t *)
51     | NCic.LetIn _ -> [Variable] (* z-reduce? *)
52     | NCic.Meta _ | NCic.Implicit _ -> assert (arity = 0); [Variable]
53     | NCic.Rel i -> [Bound (i, arity)]
54     | NCic.Sort (NCic.Prop) -> assert (arity=0); [Proposition]
55     | NCic.Sort _ -> assert (arity=0); [Datatype]
56     | NCic.Const (NReference.Ref (u,_)) -> [Constant (u, arity)]
57     | NCic.Match _ -> [Dead]
58   in 
59     aux 0
60 ;;
61
62 let compare e1 e2 =
63   match e1,e2 with
64   | Constant (u1,a1),Constant (u2,a2) -> 
65        let x = NUri.compare u1 u2 in
66        if x = 0 then Pervasives.compare a1 a2 else x
67   | e1,e2 -> Pervasives.compare e1 e2
68 ;;
69
70 let string_of_path l = String.concat "." (List.map ppelem l) ;;
71
72 end
73
74 module DiscriminationTree = 
75   Discrimination_tree.DiscriminationTreeIndexing(NCicIndexable)
76   *)