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 index_coercion (db_src,db_tgt) c src tgt arity arg =
28 let data = (c,arity,arg) in
30 prerr_endline ("INDEX:" ^
31 NCicPp.ppterm ~metasenv:[] ~subst:[] ~context:[] src ^ " ===> " ^
32 NCicPp.ppterm ~metasenv:[] ~subst:[] ~context:[] tgt ^ " := " ^
33 NCicPp.ppterm ~metasenv:[] ~subst:[] ~context:[] c);
35 let db_src = DB.index db_src src data in
36 let db_tgt = DB.index db_tgt tgt data in
42 (fun db (_,tgt,clist) ->
44 (fun db (uri,_,arg) ->
45 let c=fst (OCic2NCic.convert_term uri (CicUtil.term_of_uri uri)) in
46 let arity = match tgt with | CoercDb.Fun i -> i | _ -> 0 in
48 let cty = NCicTypeChecker.typeof ~subst:[] ~metasenv:[] [] c in
49 let scty, metasenv,_ =
50 NCicMetaSubst.saturate ~delta:max_int [] [] [] cty (arity+1)
53 | NCic.Prod (_, src, tgt) ->
55 NCicSubstitution.subst (NCic.Meta (-1,(0,NCic.Irl 0))) tgt
58 prerr_endline (Printf.sprintf "indicizzo %s (%d) : %s ===> %s"
59 (NCicPp.ppterm ~metasenv ~subst:[] ~context:[] scty) (arity+1)
60 (NCicPp.ppterm ~metasenv ~subst:[] ~context:[] src)
61 (NCicPp.ppterm ~metasenv ~subst:[] ~context:[] tgt));
66 NCicPp.ppterm ~metasenv ~subst:[] ~context:[] t);
69 index_coercion db c src tgt arity arg)
71 (DB.empty,DB.empty) (CoercDb.to_list ())
74 let empty_db = (DB.empty,DB.empty) ;;
77 let look_for_coercion (db_src,db_tgt) metasenv subst context infty expty =
78 match infty, expty with
79 | (NCic.Meta _ | NCic.Appl (NCic.Meta _::_)),
80 (NCic.Meta _ | NCic.Appl (NCic.Meta _::_)) -> []
83 prerr_endline ("LOOK FOR COERCIONS: " ^
84 NCicPp.ppterm ~metasenv ~subst ~context infty ^ " |===> " ^
85 NCicPp.ppterm ~metasenv ~subst ~context expty);
87 let set_src = DB.retrieve_unifiables db_src infty in
88 let set_tgt = DB.retrieve_unifiables db_tgt expty in
89 let candidates = CoercionSet.inter set_src set_tgt in
91 prerr_endline ("CANDIDATES: " ^
92 String.concat "," (List.map (fun (t,_,_) ->
93 NCicPp.ppterm ~metasenv ~subst ~context t)
94 (CoercionSet.elements candidates)));
98 let ty = NCicTypeChecker.typeof ~metasenv:[] ~subst:[] [] t in
99 let ty, metasenv, args =
100 NCicMetaSubst.saturate ~delta:max_int metasenv subst context ty arity
103 NCicPp.ppterm ~metasenv ~subst:[] ~context:[] ty ^ " --- " ^
104 NCicPp.ppterm ~metasenv ~subst ~context
105 (NCicUntrusted.mk_appl t args) ^ " --- " ^
106 string_of_int (List.length args) ^ " == " ^ string_of_int arg); *)
107 metasenv, NCicUntrusted.mk_appl t args, ty, List.nth args arg)
108 (CoercionSet.elements candidates)