1 (* Copyright (C) 2005, HELM Team.
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.
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.
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.
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,
22 * For details, see the HELM World-Wide-Web page,
23 * http://cs.unibo.it/helm/.
26 (* $Id: discrimination_tree.ml 8991 2008-09-19 12:47:23Z tassi $ *)
28 module CicIndexable : Discrimination_tree.Indexable
29 with type input = Cic.term and type constant_name = UriManager.uri
33 type constant_name = UriManager.uri
34 open Discrimination_tree
37 | Constant (uri,arity) ->
38 "("^UriManager.name_of_uri uri ^ "," ^ string_of_int arity^")"
40 "("^string_of_int i ^ "," ^ string_of_int arity^")"
42 | Proposition -> "Prop"
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]
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
79 let string_of_path l = String.concat "." (List.map ppelem l) ;;