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.
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_______________________________________________________________ *)
12 (* $Id: nCicRefiner.mli 9227 2008-11-21 16:00:06Z tassi $ *)
14 module COT : Set.OrderedType with type t = NCic.term * int * int =
16 type t = NCic.term * int * int
17 let compare = Pervasives.compare
20 module CoercionSet = Set.Make(COT)
23 Discrimination_tree.Make(NDiscriminationTree.NCicIndexable)(CoercionSet)
27 let empty_db = DB.empty,DB.empty
33 method set_coerc_db v = {< db = v >}
34 method set_coercion_status (o : status) = {< db = o#coerc_db >}
37 let index_coercion status c src tgt arity arg =
38 let db_src,db_tgt = status#coerc_db in
39 let data = (c,arity,arg) in
41 prerr_endline ("INDEX:" ^
42 NCicPp.ppterm ~metasenv:[] ~subst:[] ~context:[] src ^ " ===> " ^
43 NCicPp.ppterm ~metasenv:[] ~subst:[] ~context:[] tgt ^ " := " ^
44 NCicPp.ppterm ~metasenv:[] ~subst:[] ~context:[] c);
46 let db_src = DB.index db_src src data in
47 let db_tgt = DB.index db_tgt tgt data in
48 status#set_coerc_db (db_src, db_tgt)
51 let index_old_db odb (status : #status) =
53 (fun status (_,tgt,clist) ->
55 (fun status (uri,_,arg) ->
57 let c=fst (OCic2NCic.convert_term uri (CicUtil.term_of_uri uri)) in
58 let arity = match tgt with | CoercDb.Fun i -> i | _ -> 0 in
60 let cty = NCicTypeChecker.typeof ~subst:[] ~metasenv:[] [] c in
61 let scty, metasenv,_ =
62 NCicMetaSubst.saturate ~delta:max_int [] [] [] cty (arity+1)
65 | NCic.Prod (_, src, tgt) ->
67 NCicSubstitution.subst (NCic.Meta (-1,(0,NCic.Irl 0))) tgt
70 prerr_endline (Printf.sprintf "indicizzo %s (%d) : %s ===> %s"
71 (NCicPp.ppterm ~metasenv ~subst:[] ~context:[] scty) (arity+1)
72 (NCicPp.ppterm ~metasenv ~subst:[] ~context:[] src)
73 (NCicPp.ppterm ~metasenv ~subst:[] ~context:[] tgt));
78 NCicPp.ppterm ~metasenv ~subst:[] ~context:[] t);
81 index_coercion status c src tgt arity arg
83 | NCicEnvironment.BadDependency _
84 | NCicTypeChecker.TypeCheckerFailure _ -> status)
86 status (CoercDb.to_list odb)
89 let look_for_coercion status metasenv subst context infty expty =
90 let db_src,db_tgt = status#coerc_db in
91 match infty, expty with
92 | (NCic.Meta _ | NCic.Appl (NCic.Meta _::_)),
93 (NCic.Meta _ | NCic.Appl (NCic.Meta _::_)) -> []
96 prerr_endline ("LOOK FOR COERCIONS: " ^
97 NCicPp.ppterm ~metasenv ~subst ~context infty ^ " |===> " ^
98 NCicPp.ppterm ~metasenv ~subst ~context expty);
100 let set_src = DB.retrieve_unifiables db_src infty in
101 let set_tgt = DB.retrieve_unifiables db_tgt expty in
102 let candidates = CoercionSet.inter set_src set_tgt in
104 prerr_endline ("CANDIDATES: " ^
105 String.concat "," (List.map (fun (t,_,_) ->
106 NCicPp.ppterm ~metasenv ~subst ~context t)
107 (CoercionSet.elements candidates)));
110 (fun (t,arity,arg) ->
111 let ty = NCicTypeChecker.typeof ~metasenv:[] ~subst:[] [] t in
112 let ty, metasenv, args =
113 NCicMetaSubst.saturate ~delta:max_int metasenv subst context ty arity
116 NCicPp.ppterm ~metasenv ~subst:[] ~context:[] ty ^ " --- " ^
117 NCicPp.ppterm ~metasenv ~subst ~context
118 (NCicUntrusted.mk_appl t args) ^ " --- " ^
119 string_of_int (List.length args) ^ " == " ^ string_of_int arg); *)
120 metasenv, NCicUntrusted.mk_appl t args, ty, List.nth args arg)
121 (CoercionSet.elements candidates)