1
1
structure Channel_Type =
2
2
struct
3
+
4
+ fun
5
+ add_typerep_tfrees (Type (n, ts)) = Type (n, map add_typerep_tfrees ts) |
6
+ add_typerep_tfrees (TFree (n, sorts)) = TFree (n, sorts @ @{sort typerep}) |
7
+ add_typerep_tfrees (TVar (n, sorts)) = TVar (n, sorts @ @{sort typerep})
8
+
3
9
fun prove_prism_goal thy =
4
10
let
5
11
open Simplifier; open Global_Theory; open Lens_Lib
@@ -76,7 +82,7 @@ fun chantyperep_def name raw_chans ct vmap ctx =
76
82
open Syntax; open HOLogic; open Global_Theory; open Proof_Context
77
83
val ty = read_type_name {proper = true , strict = false } ctx name;
78
84
fun repl_tvars ty = map_type_tfree (fn (n, s) => TFree (the (AList.lookup (op =) vmap n), s)) ty
79
- val chans = @{print} ( map (fn (n, t) => (n, mk_typerep (repl_tvars (read_typ ctx t)))) raw_chans)
85
+ val chans = map (fn (n, t) => (n, mk_typerep (repl_tvars (read_typ ctx t)))) raw_chans
80
86
val lhs = ct $ Free (" T" , Term.itselfT ty);
81
87
val rhs = mk_chantyperep chans ctx;
82
88
val eq = check_term ctx (HOLogic.mk_Trueprop (HOLogic.mk_eq (lhs, rhs)));
@@ -105,12 +111,13 @@ fun chantyperep_instance raw_vars vars sorts name raw_chans thy =
105
111
Class.prove_instantiation_exit (fn _ => NO_CONTEXT_TACTIC ctx5 (Method_Closure.apply_method ctx5 @{method chantyperep_inst} [] [] [] ctx5 [])) ctx5
106
112
end ;
107
113
108
- fun make_chantype tvars vars sorts name chans thy =
114
+ fun make_chantype tvars sorts name chans thy =
109
115
let
110
116
open BNF_FP_Def_Sugar; open BNF_FP_Rec_Sugar_Util; open BNF_LFP; open Ctr_Sugar
111
117
open Prism_Lib; open Lens_Lib; open Local_Theory; open Specification; open Syntax; open HOLogic; open Global_Theory
112
118
val ctx = Named_Target.theory_init thy;
113
- val ctrs = map (fn (n, t) => (((Binding.empty, Binding.name (n ^ ctor_suffix)), [(Binding.empty, t)]), Mixfix.NoSyn)) chans
119
+ val ctrs = map (fn (n, t) => (((Binding.empty, Binding.name (n ^ ctor_suffix)), [(Binding.empty, add_typerep_tfrees (read_typ ctx t))]), Mixfix.NoSyn)) chans
120
+
114
121
val pnames = map fst chans
115
122
val thypfx =
116
123
case (Named_Target.locale_of ctx) of
@@ -119,12 +126,12 @@ fun make_chantype tvars vars sorts name chans thy =
119
126
val prefix = thypfx ^ name ^ " ."
120
127
val attrs = @{attributes [simp, code_unfold]}
121
128
val dummy_disc = absdummy dummyT @{term True}
122
- val ctx1 = co_datatype_cmd Least_FP construct_lfp
123
- ((K Plugin_Name.default_filter, true ),
124
- [(((((tvars , Binding.name name), Mixfix.NoSyn), ctrs), (Binding.empty, Binding.empty, Binding.empty)),[])]) ctx
129
+ val cdtvars = map ( fn (v, s) => ( NONE , (TFree (v, []), s))) (ListPair.zip (tvars, sorts))
130
+ val ctx1 = co_datatypes Least_FP construct_lfp
131
+ ((Plugin_Name.default_filter, true ), [(((((cdtvars , Binding.name name), Mixfix.NoSyn), ctrs), (Binding.empty, Binding.empty, Binding.empty)),[])]) ctx
125
132
val typ = Proof_Context.read_type_name {proper = true , strict = false } ctx1 name
126
133
val tyco = fst (dest_Type typ);
127
- val typ' = Type (tyco, map TFree (ListPair.zip (vars , sorts)))
134
+ val typ' = Type (tyco, map TFree (ListPair.zip (tvars , sorts)))
128
135
val ptyp = prismT dummyT typ'
129
136
in
130
137
(
@@ -137,7 +144,7 @@ fun make_chantype tvars vars sorts name chans thy =
137
144
(is_prefix ^ nth pnames 1 ^ ctor_suffix)
138
145
(const @{const_name comp} $ @{term Not} $ const (prefix ^ is_prefix ^ nth pnames 0 ^ ctor_suffix))) false
139
146
else I)
140
- (* The datatype also does not produce a discrimator when the length is 1 *)
147
+ (* The datatype also does not produce a discriminator when the length is 1 *)
141
148
#> (if (length pnames = 1 )
142
149
then abbreviation
143
150
Syntax.mode_default (SOME (Binding.qualify false name (Binding.name (is_prefix ^ nth pnames 0 ^ ctor_suffix)), NONE , NoSyn)) []
@@ -163,11 +170,6 @@ fun prism_has_chanrep n ctx =
163
170
Trueprop $ (const @{const_name has_chanrep} $ c)
164
171
end
165
172
166
- fun
167
- add_typerep_tfrees (Type (n, ts)) = Type (n, map add_typerep_tfrees ts) |
168
- add_typerep_tfrees (TFree (n, sorts)) = TFree (n, sorts @ @{sort typerep}) |
169
- add_typerep_tfrees (TVar (n, sorts)) = TVar (n, sorts @ @{sort typerep})
170
-
171
173
fun prism_has_chanrep_proof ctx (n, t) =
172
174
let open Simplifier; open Prism_Lib; open Syntax; open HOLogic
173
175
val d = read_term ctx (" is_" ^ n ^ " _C" )
@@ -202,18 +204,18 @@ fun prism_chanrep_proofs (name, chans) thy =
202
204
203
205
204
206
205
- fun compile_chantype ((tvars , name), chans ) thy =
207
+ fun compile_chantype ((raw_tvars , name), raw_chans ) thy =
206
208
let
207
- open Syntax
209
+ open Syntax;
208
210
val ctx = Named_Target.theory_init thy;
209
- val vars = map (fn n => " '" ^ Char.toString (Char.chr n)) (97 upto (96 + length tvars ));
210
- val sorts = map (fn t => case snd (snd t) of SOME s => read_sort ctx s @ @{sort typerep} | NONE => @{sort typerep}) tvars
211
+ val tvars = map (fn n => " '" ^ Char.toString (Char.chr n)) (97 upto (96 + length raw_tvars ));
212
+ val sorts = map (fn t => case snd (snd t) of SOME s => read_sort ctx s @ @{sort typerep} | NONE => @{sort typerep}) raw_tvars
211
213
in
212
- (make_chantype tvars vars sorts name chans #>
214
+ (make_chantype (map (fst o snd) raw_tvars) sorts name raw_chans #>
213
215
(* Generate chantyperep instance *)
214
- chantyperep_instance (map (fst o snd) tvars) vars sorts name chans #>
216
+ chantyperep_instance (map (fst o snd) raw_tvars) tvars sorts name raw_chans #>
215
217
(* Generate representations for each prism (channel) *)
216
- prism_chanrep_proofs (name, chans )) thy
218
+ prism_chanrep_proofs (name, raw_chans )) thy
217
219
end
218
220
219
221
end ;
0 commit comments