author | wenzelm |
Fri, 10 Mar 2000 01:16:19 +0100 | |
changeset 8405 | 0255394a05da |
parent 6397 | e70ae9b575cc |
child 8416 | 8eb32cd3122e |
permissions | -rw-r--r-- |
3302 | 1 |
(* Title: TFL/thry |
2 |
ID: $Id$ |
|
3 |
Author: Konrad Slind, Cambridge University Computer Laboratory |
|
4 |
Copyright 1997 University of Cambridge |
|
5 |
*) |
|
6 |
||
2112 | 7 |
structure Thry : Thry_sig (* LThry_sig *) = |
8 |
struct |
|
9 |
||
10 |
structure S = USyntax; |
|
11 |
||
12 |
fun THRY_ERR{func,mesg} = Utils.ERR{module = "Thry",func=func,mesg=mesg}; |
|
13 |
||
14 |
(*--------------------------------------------------------------------------- |
|
15 |
* Matching |
|
16 |
*---------------------------------------------------------------------------*) |
|
17 |
||
3353
9112a2efb9a3
Removal of module Mask and datatype binding with its constructor |->
paulson
parents:
3332
diff
changeset
|
18 |
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
|
19 |
fun tmbind (x,y) = (Var (x,type_of y), y) |
2112 | 20 |
in |
21 |
fun match_term thry pat ob = |
|
6397 | 22 |
let val tsig = #tsig(Sign.rep_sg(Theory.sign_of thry)) |
2112 | 23 |
val (ty_theta,tm_theta) = Pattern.match tsig (pat,ob) |
24 |
in (map tmbind tm_theta, map tybind ty_theta) |
|
25 |
end |
|
26 |
||
27 |
fun match_type thry pat ob = |
|
6397 | 28 |
map tybind(Type.typ_match (#tsig(Sign.rep_sg(Theory.sign_of thry))) ([],(pat,ob))) |
2112 | 29 |
end; |
30 |
||
31 |
||
32 |
(*--------------------------------------------------------------------------- |
|
33 |
* Typing |
|
34 |
*---------------------------------------------------------------------------*) |
|
35 |
||
6397 | 36 |
fun typecheck thry = Thm.cterm_of (Theory.sign_of thry); |
2112 | 37 |
|
38 |
||
39 |
(*--------------------------------------------------------------------------- |
|
5193 | 40 |
* Get information about datatypes |
2112 | 41 |
*---------------------------------------------------------------------------*) |
4107 | 42 |
|
5193 | 43 |
fun get_info thy ty = Symtab.lookup (DatatypePackage.get_datatypes thy, ty); |
4107 | 44 |
|
5193 | 45 |
fun match_info thy tname = |
46 |
case (DatatypePackage.case_const_of thy tname, DatatypePackage.constrs_of thy tname) of |
|
47 |
(Some case_const, Some constructors) => |
|
48 |
Some {case_const = case_const, constructors = constructors} |
|
49 |
| _ => None; |
|
2112 | 50 |
|
5193 | 51 |
fun induct_info thy tname = case get_info thy tname of |
52 |
None => None |
|
53 |
| Some {nchotomy, ...} => |
|
54 |
Some {nchotomy = nchotomy, |
|
55 |
constructors = the (DatatypePackage.constrs_of thy tname)}; |
|
2112 | 56 |
|
5193 | 57 |
fun extract_info thy = |
58 |
let val infos = map snd (Symtab.dest (DatatypePackage.get_datatypes thy)) |
|
59 |
in {case_congs = map (mk_meta_eq o #case_cong) infos, |
|
60 |
case_rewrites = flat (map (map mk_meta_eq o #case_rewrites) infos)} |
|
2112 | 61 |
end; |
62 |
||
63 |
end; (* Thry *) |