author | wenzelm |
Fri, 15 Sep 2000 16:28:04 +0200 | |
changeset 9972 | 05afcc505da3 |
parent 9867 | bf8300fa4238 |
permissions | -rw-r--r-- |
9867 | 1 |
(* Title: TFL/thry.sml |
3302 | 2 |
ID: $Id$ |
3 |
Author: Konrad Slind, Cambridge University Computer Laboratory |
|
4 |
Copyright 1997 University of Cambridge |
|
5 |
*) |
|
6 |
||
9867 | 7 |
signature Thry_sig = |
8 |
sig |
|
9 |
val match_term : theory -> term -> term |
|
10 |
-> (term*term)list * (typ*typ)list |
|
11 |
||
12 |
val match_type : theory -> typ -> typ -> (typ*typ)list |
|
13 |
||
14 |
val typecheck : theory -> term -> cterm |
|
15 |
||
16 |
(* Datatype facts of various flavours *) |
|
17 |
val match_info: theory -> string -> {constructors:term list, |
|
18 |
case_const:term} option |
|
19 |
||
20 |
val induct_info: theory -> string -> {constructors:term list, |
|
21 |
nchotomy:thm} option |
|
22 |
||
23 |
val extract_info: theory -> {case_congs:thm list, case_rewrites:thm list} |
|
24 |
||
25 |
end; |
|
26 |
||
27 |
||
2112 | 28 |
structure Thry : Thry_sig (* LThry_sig *) = |
29 |
struct |
|
30 |
||
31 |
structure S = USyntax; |
|
32 |
||
33 |
fun THRY_ERR{func,mesg} = Utils.ERR{module = "Thry",func=func,mesg=mesg}; |
|
34 |
||
35 |
(*--------------------------------------------------------------------------- |
|
36 |
* Matching |
|
37 |
*---------------------------------------------------------------------------*) |
|
38 |
||
3353
9112a2efb9a3
Removal of module Mask and datatype binding with its constructor |->
paulson
parents:
3332
diff
changeset
|
39 |
local fun tybind (x,y) = (TVar (x,["term"]) , y) |
9112a2efb9a3
Removal of module Mask and datatype binding with its constructor |->
paulson
parents:
3332
diff
changeset
|
40 |
fun tmbind (x,y) = (Var (x,type_of y), y) |
2112 | 41 |
in |
42 |
fun match_term thry pat ob = |
|
6397 | 43 |
let val tsig = #tsig(Sign.rep_sg(Theory.sign_of thry)) |
2112 | 44 |
val (ty_theta,tm_theta) = Pattern.match tsig (pat,ob) |
45 |
in (map tmbind tm_theta, map tybind ty_theta) |
|
46 |
end |
|
47 |
||
8416
8eb32cd3122e
Type.typ_match now uses Vartab instead of association lists.
berghofe
parents:
6397
diff
changeset
|
48 |
fun match_type thry pat ob = map tybind (Vartab.dest |
8eb32cd3122e
Type.typ_match now uses Vartab instead of association lists.
berghofe
parents:
6397
diff
changeset
|
49 |
(Type.typ_match (#tsig(Sign.rep_sg(Theory.sign_of thry))) (Vartab.empty, (pat,ob)))) |
2112 | 50 |
end; |
51 |
||
52 |
||
53 |
(*--------------------------------------------------------------------------- |
|
54 |
* Typing |
|
55 |
*---------------------------------------------------------------------------*) |
|
56 |
||
6397 | 57 |
fun typecheck thry = Thm.cterm_of (Theory.sign_of thry); |
2112 | 58 |
|
59 |
||
60 |
(*--------------------------------------------------------------------------- |
|
5193 | 61 |
* Get information about datatypes |
2112 | 62 |
*---------------------------------------------------------------------------*) |
4107 | 63 |
|
5193 | 64 |
fun get_info thy ty = Symtab.lookup (DatatypePackage.get_datatypes thy, ty); |
4107 | 65 |
|
5193 | 66 |
fun match_info thy tname = |
67 |
case (DatatypePackage.case_const_of thy tname, DatatypePackage.constrs_of thy tname) of |
|
68 |
(Some case_const, Some constructors) => |
|
69 |
Some {case_const = case_const, constructors = constructors} |
|
70 |
| _ => None; |
|
2112 | 71 |
|
5193 | 72 |
fun induct_info thy tname = case get_info thy tname of |
73 |
None => None |
|
74 |
| Some {nchotomy, ...} => |
|
75 |
Some {nchotomy = nchotomy, |
|
76 |
constructors = the (DatatypePackage.constrs_of thy tname)}; |
|
2112 | 77 |
|
5193 | 78 |
fun extract_info thy = |
79 |
let val infos = map snd (Symtab.dest (DatatypePackage.get_datatypes thy)) |
|
80 |
in {case_congs = map (mk_meta_eq o #case_cong) infos, |
|
81 |
case_rewrites = flat (map (map mk_meta_eq o #case_rewrites) infos)} |
|
2112 | 82 |
end; |
83 |
||
84 |
end; (* Thry *) |