]> matita.cs.unibo.it Git - helm.git/blob - helm/ocaml/cic_proof_checking/cicRecord.ml
ocaml 3.09 transition
[helm.git] / helm / ocaml / cic_proof_checking / cicRecord.ml
1 (* Copyright (C) 2004-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://helm.cs.unibo.it/
24  *)
25
26 let rec_ty uri leftno  = 
27   let rec_ty = Cic.MutInd (uri,0,[]) in
28   if leftno = 0 then rec_ty else
29     Cic.Appl (rec_ty :: (CicUtil.mk_rels leftno 0))
30
31 let generate_one_proj uri params paramsno fields t i =
32  let mk_lambdas l start = 
33   List.fold_right (fun (name,ty) acc -> 
34     Cic.Lambda (Cic.Name name,ty,acc)) l start in
35  let recty = rec_ty uri paramsno in
36  let outtype = Cic.Lambda (Cic.Name "w'", CicSubstitution.lift 1 recty, t) in
37   Some
38    (mk_lambdas params
39      (Cic.Lambda (Cic.Name "w", recty,
40        Cic.MutCase (uri,0,outtype, Cic.Rel 1, 
41         [mk_lambdas fields (Cic.Rel i)]))))
42
43 let projections_of uri field_names =
44  let buri = UriManager.buri_of_uri uri in
45  let obj,ugraph = CicEnvironment.get_cooked_obj CicUniv.empty_ugraph uri in
46   match obj with
47      Cic.InductiveDefinition ([_,_,sort,[_,ty]],params,paramsno,_) ->
48       assert (params = []); (* general case not implemented *)
49       let leftparams,ty =
50        let rec aux =
51         function
52            0,ty -> [],ty
53          | n,Cic.Prod (Cic.Name name,s,t) ->
54             let leftparams,ty = aux (n - 1,t) in
55              (name,s)::leftparams,ty
56          | _,_ -> assert false
57        in
58         aux (paramsno,ty)
59       in
60       let fields =
61        let rec aux =
62         function
63            Cic.MutInd _, []
64          | Cic.Appl _,   [] -> []
65          | Cic.Prod (_,s,t), name::tl -> (name,s)::aux (t,tl)
66          | _,_ -> assert false
67        in
68         aux ((CicSubstitution.lift 1 ty),field_names)
69       in
70        let rec aux i =
71         function
72            Cic.MutInd _, []
73          | Cic.Appl _,   [] -> []
74          | Cic.Prod (_,s,t), name::tl ->
75             (match generate_one_proj uri leftparams paramsno fields s i with
76                 Some p ->
77                  let puri =
78                   UriManager.uri_of_string (buri ^ "/" ^ name ^ ".con")
79                  in
80                   (puri,name,p) ::
81                     aux (i - 1)
82                      (CicSubstitution.subst
83                        (Cic.Appl
84                          (Cic.Const (puri,[]) ::
85                            CicUtil.mk_rels paramsno 2 @ [Cic.Rel 1])
86                        ) t, tl)
87               | None -> assert false)
88          | _,_ -> assert false
89        in
90         aux (List.length fields) (CicSubstitution.lift 2 ty,field_names)
91    | _ -> assert false