author | oheimb |
Mon, 27 Oct 1997 11:34:33 +0100 | |
changeset 4008 | 2444085532c6 |
parent 3622 | 85898be702b2 |
child 4030 | ca44afcc259c |
permissions | -rw-r--r-- |
2445
51993fea433f
removed Holcfb.thy and Holcfb.ML, moving classical3 to HOL.ML as classical2
oheimb
parents:
2267
diff
changeset
|
1 |
(* Title: HOLCF/domain/interface.ML |
51993fea433f
removed Holcfb.thy and Holcfb.ML, moving classical3 to HOL.ML as classical2
oheimb
parents:
2267
diff
changeset
|
2 |
ID: $Id$ |
51993fea433f
removed Holcfb.thy and Holcfb.ML, moving classical3 to HOL.ML as classical2
oheimb
parents:
2267
diff
changeset
|
3 |
Author : David von Oheimb |
51993fea433f
removed Holcfb.thy and Holcfb.ML, moving classical3 to HOL.ML as classical2
oheimb
parents:
2267
diff
changeset
|
4 |
Copyright 1995, 1996 TU Muenchen |
51993fea433f
removed Holcfb.thy and Holcfb.ML, moving classical3 to HOL.ML as classical2
oheimb
parents:
2267
diff
changeset
|
5 |
|
51993fea433f
removed Holcfb.thy and Holcfb.ML, moving classical3 to HOL.ML as classical2
oheimb
parents:
2267
diff
changeset
|
6 |
parser for domain section |
1274 | 7 |
*) |
8 |
||
9 |
local |
|
10 |
open ThyParse; |
|
11 |
open Domain_Library; |
|
12 |
||
1637
b8a8ae2e5de1
Updated: 01-Mar-96 when functional strictified, copy_def based on when_def
oheimb
parents:
1461
diff
changeset
|
13 |
(* --- generation of bindings for axioms and theorems in trailer of .thy.ML - *) |
1274 | 14 |
|
1637
b8a8ae2e5de1
Updated: 01-Mar-96 when functional strictified, copy_def based on when_def
oheimb
parents:
1461
diff
changeset
|
15 |
fun gt_ax name = "get_axiom thy " ^ quote name; |
b8a8ae2e5de1
Updated: 01-Mar-96 when functional strictified, copy_def based on when_def
oheimb
parents:
1461
diff
changeset
|
16 |
fun gen_val dname name = "val "^name^" = "^ gt_ax (dname^"_"^name)^";"; |
b8a8ae2e5de1
Updated: 01-Mar-96 when functional strictified, copy_def based on when_def
oheimb
parents:
1461
diff
changeset
|
17 |
fun gen_vall name l = "val "^name^" = "^ mk_list l^";"; |
1274 | 18 |
val rews1 = "iso_rews @ when_rews @\n\ |
1637
b8a8ae2e5de1
Updated: 01-Mar-96 when functional strictified, copy_def based on when_def
oheimb
parents:
1461
diff
changeset
|
19 |
\con_rews @ sel_rews @ dis_rews @ dists_le @ dists_eq @\n\ |
b8a8ae2e5de1
Updated: 01-Mar-96 when functional strictified, copy_def based on when_def
oheimb
parents:
1461
diff
changeset
|
20 |
\copy_rews"; |
1274 | 21 |
|
22 |
fun gen_domain eqname num ((dname,_), cons') = let |
|
23 |
val axioms1 = ["abs_iso", "rep_iso", "when_def"]; |
|
1637
b8a8ae2e5de1
Updated: 01-Mar-96 when functional strictified, copy_def based on when_def
oheimb
parents:
1461
diff
changeset
|
24 |
(* con_defs , sel_defs, dis_defs *) |
1274 | 25 |
val axioms2 = ["copy_def"]; |
26 |
val theorems = |
|
1637
b8a8ae2e5de1
Updated: 01-Mar-96 when functional strictified, copy_def based on when_def
oheimb
parents:
1461
diff
changeset
|
27 |
"iso_rews, exhaust, cases, when_rews, con_rews, sel_rews, dis_rews,\n \ |
b8a8ae2e5de1
Updated: 01-Mar-96 when functional strictified, copy_def based on when_def
oheimb
parents:
1461
diff
changeset
|
28 |
\dists_le, dists_eq, inverts, injects, copy_rews"; |
1274 | 29 |
in |
30 |
"structure "^dname^" = struct\n"^ |
|
31 |
cat_lines(map (gen_val dname) axioms1)^"\n"^ |
|
32 |
gen_vall"con_defs"(map(fn (con,_,_) => gt_ax(strip_esc con^"_def")) cons')^"\n"^ |
|
33 |
gen_vall"sel_defs"(flat(map (fn (_,_,args) => map (fn (_,sel,_) => |
|
1637
b8a8ae2e5de1
Updated: 01-Mar-96 when functional strictified, copy_def based on when_def
oheimb
parents:
1461
diff
changeset
|
34 |
gt_ax(sel^"_def")) args) cons'))^"\n"^ |
1274 | 35 |
gen_vall"dis_defs"(map(fn (con,_,_) => gt_ax(dis_name_ con^"_def")) |
1637
b8a8ae2e5de1
Updated: 01-Mar-96 when functional strictified, copy_def based on when_def
oheimb
parents:
1461
diff
changeset
|
36 |
cons')^"\n"^ |
1274 | 37 |
cat_lines(map (gen_val dname) axioms2)^"\n"^ |
38 |
"val ("^ theorems ^") =\n\ |
|
39 |
\Domain_Theorems.theorems thy "^eqname^";\n" ^ |
|
40 |
(if num > 1 then "val rews = " ^rews1 ^";\n" else "") |
|
41 |
end; |
|
42 |
||
4008 | 43 |
fun mk_domain eqs'' = let |
44 |
val num = length eqs''; |
|
45 |
val dtnvs = map fst eqs''; |
|
1274 | 46 |
val dnames = map fst dtnvs; |
47 |
val comp_dname = implode (separate "_" dnames); |
|
2267 | 48 |
val conss' = ListPair.map |
4008 | 49 |
(fn (dname,cons'') => let fun sel n m = upd_second |
2267 | 50 |
(fn None => dname^"_sel_"^(string_of_int n)^ |
4008 | 51 |
"_"^(string_of_int m) |
2267 | 52 |
| Some s => s) |
53 |
fun fill_sels n con = upd_third (mapn (sel n) 1) con; |
|
54 |
in mapn fill_sels 1 cons'' end) |
|
4008 | 55 |
(dnames, map snd eqs''); |
1274 | 56 |
val eqs' = dtnvs~~conss'; |
57 |
||
1637
b8a8ae2e5de1
Updated: 01-Mar-96 when functional strictified, copy_def based on when_def
oheimb
parents:
1461
diff
changeset
|
58 |
(* ----- string for calling add_domain -------------------------------------- *) |
1284 | 59 |
|
1637
b8a8ae2e5de1
Updated: 01-Mar-96 when functional strictified, copy_def based on when_def
oheimb
parents:
1461
diff
changeset
|
60 |
val thy_ext_string = let |
2240 | 61 |
fun mk_conslist cons' = |
4008 | 62 |
mk_list (map (fn (c,syn,ts)=> |
63 |
mk_triple(quote c, syn, mk_list (map (fn (b,s ,tp) => |
|
64 |
mk_triple(Bool.toString b, quote s, tp)) ts))) cons'); |
|
1637
b8a8ae2e5de1
Updated: 01-Mar-96 when functional strictified, copy_def based on when_def
oheimb
parents:
1461
diff
changeset
|
65 |
in "val (thy, "^comp_dname^"_equations) = thy |> Domain_Extender.add_domain \n" |
4008 | 66 |
^ mk_pair(quote comp_dname, mk_list(map (fn ((n,vs),cs) => |
67 |
mk_pair (mk_pair (quote n, mk_list vs), |
|
68 |
mk_conslist cs)) eqs')) |
|
1637
b8a8ae2e5de1
Updated: 01-Mar-96 when functional strictified, copy_def based on when_def
oheimb
parents:
1461
diff
changeset
|
69 |
^ ";\nval thy = thy" |
b8a8ae2e5de1
Updated: 01-Mar-96 when functional strictified, copy_def based on when_def
oheimb
parents:
1461
diff
changeset
|
70 |
end; |
b8a8ae2e5de1
Updated: 01-Mar-96 when functional strictified, copy_def based on when_def
oheimb
parents:
1461
diff
changeset
|
71 |
|
4008 | 72 |
(* ----- string for calling (comp_)theorems and producing the structures ---- *) |
1637
b8a8ae2e5de1
Updated: 01-Mar-96 when functional strictified, copy_def based on when_def
oheimb
parents:
1461
diff
changeset
|
73 |
|
b8a8ae2e5de1
Updated: 01-Mar-96 when functional strictified, copy_def based on when_def
oheimb
parents:
1461
diff
changeset
|
74 |
val val_gen_string = let |
b8a8ae2e5de1
Updated: 01-Mar-96 when functional strictified, copy_def based on when_def
oheimb
parents:
1461
diff
changeset
|
75 |
fun plural s = if num > 1 then s^"s" else "["^s^"]"; |
b8a8ae2e5de1
Updated: 01-Mar-96 when functional strictified, copy_def based on when_def
oheimb
parents:
1461
diff
changeset
|
76 |
val comp_axioms = [(* copy, *) "reach", "take_def", "finite_def" |
b8a8ae2e5de1
Updated: 01-Mar-96 when functional strictified, copy_def based on when_def
oheimb
parents:
1461
diff
changeset
|
77 |
(*, "bisim_def" *)]; |
b8a8ae2e5de1
Updated: 01-Mar-96 when functional strictified, copy_def based on when_def
oheimb
parents:
1461
diff
changeset
|
78 |
val comp_theorems = "take_rews, " ^ implode (separate ", " (map plural |
b8a8ae2e5de1
Updated: 01-Mar-96 when functional strictified, copy_def based on when_def
oheimb
parents:
1461
diff
changeset
|
79 |
["take_lemma","finite"]))^", finite_ind, ind, coind"; |
b8a8ae2e5de1
Updated: 01-Mar-96 when functional strictified, copy_def based on when_def
oheimb
parents:
1461
diff
changeset
|
80 |
fun eqname n = "(hd(funpow "^string_of_int n^" tl "^comp_dname^"_equations), " |
b8a8ae2e5de1
Updated: 01-Mar-96 when functional strictified, copy_def based on when_def
oheimb
parents:
1461
diff
changeset
|
81 |
^comp_dname^"_equations)"; |
b8a8ae2e5de1
Updated: 01-Mar-96 when functional strictified, copy_def based on when_def
oheimb
parents:
1461
diff
changeset
|
82 |
fun collect sep name = if num = 1 then name else |
b8a8ae2e5de1
Updated: 01-Mar-96 when functional strictified, copy_def based on when_def
oheimb
parents:
1461
diff
changeset
|
83 |
implode (separate sep (map (fn s => s^"."^name) dnames)); |
1274 | 84 |
in |
1637
b8a8ae2e5de1
Updated: 01-Mar-96 when functional strictified, copy_def based on when_def
oheimb
parents:
1461
diff
changeset
|
85 |
implode (separate "end; (* struct *)\n\n" |
b8a8ae2e5de1
Updated: 01-Mar-96 when functional strictified, copy_def based on when_def
oheimb
parents:
1461
diff
changeset
|
86 |
(mapn (fn n => gen_domain (eqname n) num) 0 eqs'))^(if num > 1 then |
b8a8ae2e5de1
Updated: 01-Mar-96 when functional strictified, copy_def based on when_def
oheimb
parents:
1461
diff
changeset
|
87 |
"end; (* struct *)\n\n\ |
b8a8ae2e5de1
Updated: 01-Mar-96 when functional strictified, copy_def based on when_def
oheimb
parents:
1461
diff
changeset
|
88 |
\structure "^comp_dname^" = struct\n" else "") ^ |
b8a8ae2e5de1
Updated: 01-Mar-96 when functional strictified, copy_def based on when_def
oheimb
parents:
1461
diff
changeset
|
89 |
(if num > 1 then gen_val comp_dname "copy_def" ^"\n" else "") ^ |
b8a8ae2e5de1
Updated: 01-Mar-96 when functional strictified, copy_def based on when_def
oheimb
parents:
1461
diff
changeset
|
90 |
implode ((map (fn s => gen_vall (plural s) |
b8a8ae2e5de1
Updated: 01-Mar-96 when functional strictified, copy_def based on when_def
oheimb
parents:
1461
diff
changeset
|
91 |
(map (fn dn => gt_ax(dn ^ "_" ^ s)) dnames) ^"\n") comp_axioms)) ^ |
b8a8ae2e5de1
Updated: 01-Mar-96 when functional strictified, copy_def based on when_def
oheimb
parents:
1461
diff
changeset
|
92 |
gen_val comp_dname "bisim_def" ^"\n\ |
1274 | 93 |
\val ("^ comp_theorems ^") =\n\ |
1637
b8a8ae2e5de1
Updated: 01-Mar-96 when functional strictified, copy_def based on when_def
oheimb
parents:
1461
diff
changeset
|
94 |
\Domain_Theorems.comp_theorems thy \ |
b8a8ae2e5de1
Updated: 01-Mar-96 when functional strictified, copy_def based on when_def
oheimb
parents:
1461
diff
changeset
|
95 |
\(" ^ quote comp_dname ^ ","^ comp_dname ^"_equations,\n\ |
b8a8ae2e5de1
Updated: 01-Mar-96 when functional strictified, copy_def based on when_def
oheimb
parents:
1461
diff
changeset
|
96 |
\ ["^collect " ," "cases" ^"],\n\ |
b8a8ae2e5de1
Updated: 01-Mar-96 when functional strictified, copy_def based on when_def
oheimb
parents:
1461
diff
changeset
|
97 |
\ "^collect "@" "con_rews " ^",\n\ |
b8a8ae2e5de1
Updated: 01-Mar-96 when functional strictified, copy_def based on when_def
oheimb
parents:
1461
diff
changeset
|
98 |
\ "^collect " @" "copy_rews" ^");\n\ |
b8a8ae2e5de1
Updated: 01-Mar-96 when functional strictified, copy_def based on when_def
oheimb
parents:
1461
diff
changeset
|
99 |
\val rews = "^(if num>1 then collect" @ " "rews"else rews1)^ " @ take_rews;\n\ |
b8a8ae2e5de1
Updated: 01-Mar-96 when functional strictified, copy_def based on when_def
oheimb
parents:
1461
diff
changeset
|
100 |
\end; (* struct *)" |
b8a8ae2e5de1
Updated: 01-Mar-96 when functional strictified, copy_def based on when_def
oheimb
parents:
1461
diff
changeset
|
101 |
end; |
b8a8ae2e5de1
Updated: 01-Mar-96 when functional strictified, copy_def based on when_def
oheimb
parents:
1461
diff
changeset
|
102 |
in (thy_ext_string, val_gen_string) end; |
b8a8ae2e5de1
Updated: 01-Mar-96 when functional strictified, copy_def based on when_def
oheimb
parents:
1461
diff
changeset
|
103 |
|
b8a8ae2e5de1
Updated: 01-Mar-96 when functional strictified, copy_def based on when_def
oheimb
parents:
1461
diff
changeset
|
104 |
(* ----- strings for calling add_gen_by and producing the value binding ----------- *) |
1274 | 105 |
|
106 |
fun mk_gen_by (finite,eqs) = let |
|
107 |
val typs = map fst eqs; |
|
108 |
val cnstrss = map snd eqs; |
|
109 |
val tname = implode (separate "_" typs) in |
|
1637
b8a8ae2e5de1
Updated: 01-Mar-96 when functional strictified, copy_def based on when_def
oheimb
parents:
1461
diff
changeset
|
110 |
("|> Domain_Extender.add_gen_by " |
2240 | 111 |
^ mk_pair(mk_pair(quote tname, Bool.toString finite), |
1637
b8a8ae2e5de1
Updated: 01-Mar-96 when functional strictified, copy_def based on when_def
oheimb
parents:
1461
diff
changeset
|
112 |
mk_pair(mk_list(map quote typs), |
b8a8ae2e5de1
Updated: 01-Mar-96 when functional strictified, copy_def based on when_def
oheimb
parents:
1461
diff
changeset
|
113 |
mk_list (map (fn cns => mk_list(map quote cns)) cnstrss))), |
b8a8ae2e5de1
Updated: 01-Mar-96 when functional strictified, copy_def based on when_def
oheimb
parents:
1461
diff
changeset
|
114 |
"val "^tname^"_induct = " ^gt_ax (tname^"_induct")^";") end; |
1274 | 115 |
|
116 |
(* ----- parser for domain declaration equation ----------------------------------- *) |
|
117 |
||
2445
51993fea433f
removed Holcfb.thy and Holcfb.ML, moving classical3 to HOL.ML as classical2
oheimb
parents:
2267
diff
changeset
|
118 |
val name' = name >> strip_quotes; |
51993fea433f
removed Holcfb.thy and Holcfb.ML, moving classical3 to HOL.ML as classical2
oheimb
parents:
2267
diff
changeset
|
119 |
val type_var' = type_var >> strip_quotes; |
4008 | 120 |
fun esc_quote s = let fun esc [] = [] |
121 |
| esc ("\""::xs) = esc xs |
|
122 |
| esc ("[" ::xs) = "{"::esc xs |
|
123 |
| esc ("]" ::xs) = "}"::esc xs |
|
124 |
| esc (x ::xs) = x ::esc xs |
|
125 |
in implode (esc (explode s)) end; |
|
126 |
val tvar = (type_var' ^^ optional ($$ "::" ^^ (sort >> esc_quote)) "") >> quote; |
|
127 |
fun type_args l = (tvar >> (fn x => [x]) |
|
128 |
|| "(" $$-- !! (list1 tvar --$$ ")") |
|
129 |
|| empty >> K []) l |
|
130 |
fun con_typ l = (type_args -- name' >> (fn (x,y) => (y,x))) l |
|
131 |
(* here ident may be used instead of name' |
|
132 |
to avoid ambiguity with standard mixfix option *) |
|
1274 | 133 |
val domain_arg = "(" $$-- (optional ($$ "lazy" >> K true) false) |
2445
51993fea433f
removed Holcfb.thy and Holcfb.ML, moving classical3 to HOL.ML as classical2
oheimb
parents:
2267
diff
changeset
|
134 |
-- (optional ((name' >> Some) --$$ "::") None) |
1637
b8a8ae2e5de1
Updated: 01-Mar-96 when functional strictified, copy_def based on when_def
oheimb
parents:
1461
diff
changeset
|
135 |
-- typ --$$ ")" >> (fn ((lazy,sel),tp) => (lazy,sel,tp)) |
4008 | 136 |
|| typ >> (fn x => (false,None,x)) |
2445
51993fea433f
removed Holcfb.thy and Holcfb.ML, moving classical3 to HOL.ML as classical2
oheimb
parents:
2267
diff
changeset
|
137 |
val domain_cons = name' -- !! (repeat domain_arg) |
1637
b8a8ae2e5de1
Updated: 01-Mar-96 when functional strictified, copy_def based on when_def
oheimb
parents:
1461
diff
changeset
|
138 |
-- ThyOps.opt_cmixfix |
b8a8ae2e5de1
Updated: 01-Mar-96 when functional strictified, copy_def based on when_def
oheimb
parents:
1461
diff
changeset
|
139 |
>> (fn ((con,args),syn) => (con,syn,args)); |
1274 | 140 |
in |
141 |
val domain_decl = (enum1 "," (con_typ --$$ "=" -- !! |
|
4008 | 142 |
(enum1 "|" domain_cons))) >> mk_domain; |
1274 | 143 |
val gen_by_decl = (optional ($$ "finite" >> K true) false) -- |
2445
51993fea433f
removed Holcfb.thy and Holcfb.ML, moving classical3 to HOL.ML as classical2
oheimb
parents:
2267
diff
changeset
|
144 |
(enum1 "," (name' --$$ "by" -- !! |
51993fea433f
removed Holcfb.thy and Holcfb.ML, moving classical3 to HOL.ML as classical2
oheimb
parents:
2267
diff
changeset
|
145 |
(enum1 "|" name'))) >> mk_gen_by; |
1274 | 146 |
|
3622 | 147 |
val _ = ThySyn.add_syntax |
148 |
["lazy", "by", "finite"] |
|
149 |
[("domain", domain_decl), ("generated", gen_by_decl)] |
|
1274 | 150 |
|
3622 | 151 |
end; (* local *) |