217 binder |
150 binder |
218 bv5 |
151 bv5 |
219 where |
152 where |
220 "bv5 Lnil = {}" |
153 "bv5 Lnil = {}" |
221 | "bv5 (Lcons n t ltl) = {atom n} \<union> (bv5 ltl)" |
154 | "bv5 (Lcons n t ltl) = {atom n} \<union> (bv5 ltl)" |
222 |
|
223 (* example 6 from Terms.thy *) |
|
224 |
|
225 (* BV is not respectful, needs to fail*) |
|
226 nominal_datatype trm6 = |
|
227 Vr6 "name" |
|
228 | Lm6 x::"name" t::"trm6" bind x in t |
|
229 | Lt6 left::"trm6" right::"trm6" bind "bv6 left" in right |
|
230 binder |
|
231 bv6 |
|
232 where |
|
233 "bv6 (Vr6 n) = {}" |
|
234 | "bv6 (Lm6 n t) = {atom n} \<union> bv6 t" |
|
235 | "bv6 (Lt6 l r) = bv6 l \<union> bv6 r" |
|
236 (* example 7 from Terms.thy *) |
|
237 |
|
238 (* BV is not respectful, needs to fail*) |
|
239 nominal_datatype trm7 = |
|
240 Vr7 "name" |
|
241 | Lm7 l::"name" r::"trm7" bind l in r |
|
242 | Lt7 l::"trm7" r::"trm7" bind "bv7 l" in r |
|
243 binder |
|
244 bv7 |
|
245 where |
|
246 "bv7 (Vr7 n) = {atom n}" |
|
247 | "bv7 (Lm7 n t) = bv7 t - {atom n}" |
|
248 | "bv7 (Lt7 l r) = bv7 l \<union> bv7 r" |
|
249 |
|
250 (* example 8 from Terms.thy *) |
|
251 |
|
252 nominal_datatype foo8 = |
|
253 Foo0 "name" |
|
254 | Foo1 b::"bar8" f::"foo8" bind "bv8 b" in f --"check fo error if this is called foo" |
|
255 and bar8 = |
|
256 Bar0 "name" |
|
257 | Bar1 "name" s::"name" b::"bar8" bind s in b |
|
258 binder |
|
259 bv8 |
|
260 where |
|
261 "bv8 (Bar0 x) = {}" |
|
262 | "bv8 (Bar1 v x b) = {atom v}" |
|
263 |
|
264 (* example 9 from Terms.thy *) |
|
265 |
|
266 (* BV is not respectful, needs to fail*) |
|
267 nominal_datatype lam9 = |
|
268 Var9 "name" |
|
269 | Lam9 n::"name" l::"lam9" bind n in l |
|
270 and bla9 = |
|
271 Bla9 f::"lam9" s::"lam9" bind "bv9 f" in s |
|
272 binder |
|
273 bv9 |
|
274 where |
|
275 "bv9 (Var9 x) = {}" |
|
276 | "bv9 (Lam9 x b) = {atom x}" |
|
277 |
155 |
278 (* example from my PHD *) |
156 (* example from my PHD *) |
279 |
157 |
280 atom_decl coname |
158 atom_decl coname |
281 |
159 |
344 | "Cbinders (Type2 t T) = {atom t}" |
222 | "Cbinders (Type2 t T) = {atom t}" |
345 | "Cbinders (SStru x S) = {atom x}" |
223 | "Cbinders (SStru x S) = {atom x}" |
346 | "Cbinders (SVal v T) = {atom v}" |
224 | "Cbinders (SVal v T) = {atom v}" |
347 |
225 |
348 |
226 |
|
227 (* example 3 from Peter Sewell's bestiary *) |
|
228 nominal_datatype exp = |
|
229 VarP "name" |
|
230 | AppP "exp" "exp" |
|
231 | LamP x::"name" e::"exp" bind x in e |
|
232 | LetP x::"name" p::"pat3" e1::"exp" e2::"exp" bind x in e2, bind "bp' p" in e1 |
|
233 and pat3 = |
|
234 PVar "name" |
|
235 | PUnit |
|
236 | PPair "pat3" "pat3" |
|
237 binder |
|
238 bp' :: "pat3 \<Rightarrow> atom set" |
|
239 where |
|
240 "bp' (PVar x) = {atom x}" |
|
241 | "bp' (PUnit) = {}" |
|
242 | "bp' (PPair p1 p2) = bp' p1 \<union> bp' p2" |
|
243 thm alpha_exp_raw_alpha_pat3_raw_alpha_bp'_raw.intros |
|
244 |
|
245 (* example 6 from Peter Sewell's bestiary *) |
|
246 nominal_datatype exp6 = |
|
247 EVar name |
|
248 | EPair exp6 exp6 |
|
249 | ELetRec x::name p::pat6 e1::exp6 e2::exp6 bind x in e1, bind x in e2, bind "bp6 p" in e1 |
|
250 and pat6 = |
|
251 PVar' name |
|
252 | PUnit' |
|
253 | PPair' pat6 pat6 |
|
254 binder |
|
255 bp6 :: "pat6 \<Rightarrow> atom set" |
|
256 where |
|
257 "bp6 (PVar' x) = {atom x}" |
|
258 | "bp6 (PUnit') = {}" |
|
259 | "bp6 (PPair' p1 p2) = bp6 p1 \<union> bp6 p2" |
|
260 thm alpha_exp6_raw_alpha_pat6_raw_alpha_bp6_raw.intros |
|
261 |
|
262 (* THE REST ARE NOT SUPPOSED TO WORK YET *) |
|
263 |
|
264 (* example 7 from Peter Sewell's bestiary *) |
|
265 nominal_datatype exp7 = |
|
266 EVar name |
|
267 | EUnit |
|
268 | EPair exp7 exp7 |
|
269 | ELetRec l::lrbs e::exp7 bind "b7s l" in e, bind "b7s l" in l |
|
270 and lrb = |
|
271 Assign name exp7 |
|
272 and lrbs = |
|
273 Single lrb |
|
274 | More lrb lrbs |
|
275 binder |
|
276 b7 :: "lrb \<Rightarrow> atom set" and |
|
277 b7s :: "lrbs \<Rightarrow> atom set" |
|
278 where |
|
279 "b7 (Assign x e) = {atom x}" |
|
280 | "b7s (Single a) = b7 a" |
|
281 | "b7s (More a as) = (b7 a) \<union> (b7s as)" |
|
282 thm alpha_exp7_raw_alpha_lrb_raw_alpha_lrbs_raw.intros |
|
283 |
|
284 (* example 8 from Peter Sewell's bestiary *) |
|
285 nominal_datatype exp8 = |
|
286 EVar name |
|
287 | EUnit |
|
288 | EPair exp8 exp8 |
|
289 | ELetRec l::lrbs8 e::exp8 bind "b_lrbs8 l" in e, bind "b_lrbs8 l" in l |
|
290 and fnclause = |
|
291 K x::name p::pat8 e::exp8 bind "b_pat p" in e |
|
292 and fnclauses = |
|
293 S fnclause |
|
294 | ORs fnclause fnclauses |
|
295 and lrb8 = |
|
296 Clause fnclauses |
|
297 and lrbs8 = |
|
298 Single lrb8 |
|
299 | More lrb8 lrbs8 |
|
300 and pat8 = |
|
301 PVar name |
|
302 | PUnit |
|
303 | PPair pat8 pat8 |
|
304 binder |
|
305 b_lrbs8 :: "lrbs8 \<Rightarrow> atom set" and |
|
306 b_pat :: "pat8 \<Rightarrow> atom set" and |
|
307 b_fnclauses :: "fnclauses \<Rightarrow> atom set" and |
|
308 b_fnclause :: "fnclause \<Rightarrow> atom set" and |
|
309 b_lrb8 :: "lrb8 \<Rightarrow> atom set" |
|
310 where |
|
311 "b_lrbs8 (Single l) = b_lrb8 l" |
|
312 | "b_lrbs8 (More l ls) = b_lrb8 l \<union> b_lrbs8 ls" |
|
313 | "b_pat (PVar x) = {atom x}" |
|
314 | "b_pat (PUnit) = {}" |
|
315 | "b_pat (PPair p1 p2) = b_pat p1 \<union> b_pat p2" |
|
316 | "b_fnclauses (S fc) = (b_fnclause fc)" |
|
317 | "b_fnclauses (ORs fc fcs) = (b_fnclause fc) \<union> (b_fnclauses fcs)" |
|
318 | "b_lrb8 (Clause fcs) = (b_fnclauses fcs)" |
|
319 | "b_fnclause (K x pat exp8) = {atom x}" |
|
320 thm alpha_exp8_raw_alpha_fnclause_raw_alpha_fnclauses_raw_alpha_lrb8_raw_alpha_lrbs8_raw_alpha_pat8_raw.intros |
|
321 |
|
322 (* example 4 from Terms.thy *) |
|
323 (* fv_eqvt does not work, we need to repaire defined permute functions |
|
324 defined fv and defined alpha... *) |
|
325 nominal_datatype trm4 = |
|
326 Vr4 "name" |
|
327 | Ap4 "trm4" "trm4 list" |
|
328 | Lm4 x::"name" t::"trm4" bind x in t |
|
329 |
|
330 thm alpha_trm4_raw_alpha_trm4_raw_list.intros[no_vars] |
|
331 thm fv_trm4_raw_fv_trm4_raw_list.simps[no_vars] |
|
332 |
349 (* core haskell *) |
333 (* core haskell *) |
350 print_theorems |
|
351 |
|
352 atom_decl var |
334 atom_decl var |
353 atom_decl tvar |
335 atom_decl tvar |
354 |
336 |
355 |
|
356 (* there are types, coercion types and regular types *) |
337 (* there are types, coercion types and regular types *) |
357 nominal_datatype tkind = |
338 nominal_datatype tkind = |
358 KStar |
339 KStar |
359 | KFun "tkind" "tkind" |
340 | KFun "tkind" "tkind" |
360 and ckind = |
341 and ckind = |
361 CKEq "ty" "ty" |
342 CKEq "ty" "ty" |
362 and ty = |
343 and ty = |
363 TVar "tvar" |
344 TVar "tvar" |
364 | TC "string" |
345 | TC "string" |
365 | TApp "ty" "ty" |
346 | TApp "ty" "ty" |
366 | TFun "string" "ty list" |
347 | TFun "string" "ty list" |
386 typedecl kind |
367 typedecl kind |
387 |
368 |
388 instance ty and kind:: pt |
369 instance ty and kind:: pt |
389 sorry |
370 sorry |
390 |
371 |
391 abbreviation |
372 abbreviation |
392 "atoms A \<equiv> atom ` A" |
373 "atoms A \<equiv> atom ` A" |
393 |
374 |
394 nominal_datatype trm = |
375 nominal_datatype trm = |
395 Var "var" |
376 Var "var" |
396 | C "string" |
377 | C "string" |
397 | LAM tv::"tvar" "kind" t::"trm" bind tv in t |
378 | LAM tv::"tvar" "kind" t::"trm" bind tv in t |
398 | APP "trm" "ty" |
379 | APP "trm" "ty" |
399 | Lam v::"var" "ty" t::"trm" bind v in t |
380 | Lam v::"var" "ty" t::"trm" bind v in t |
400 | App "trm" "trm" |
381 | App "trm" "trm" |
401 | Let x::"var" "ty" "trm" t::"trm" bind x in t |
382 | Let x::"var" "ty" "trm" t::"trm" bind x in t |
402 | Case "trm" "assoc list" |
383 | Case "trm" "assoc list" |
403 | Cast "trm" "ty" --"ty is supposed to be a coercion type only" |
384 | Cast "trm" "ty" --"ty is supposed to be a coercion type only" |
404 and assoc = |
385 and assoc = |
405 A p::"pat" t::"trm" bind "bv p" in t |
386 A p::"pat" t::"trm" bind "bv p" in t |
406 and pat = |
387 and pat = |
407 K "string" "(tvar \<times> kind) list" "(var \<times> ty) list" |
388 K "string" "(tvar \<times> kind) list" "(var \<times> ty) list" |
408 binder |
389 binder |
409 bv :: "pat \<Rightarrow> atom set" |
390 bv :: "pat \<Rightarrow> atom set" |
410 where |
391 where |
411 "bv (K s ts vs) = (atoms (set (map fst ts))) \<union> (atoms (set (map fst vs)))" |
392 "bv (K s ts vs) = (atoms (set (map fst ts))) \<union> (atoms (set (map fst vs)))" |
412 |
393 |
413 (* |
394 (* |
414 compat (K s ts vs) pi (K s' ts' vs') == |
395 compat (K s ts vs) pi (K s' ts' vs') == |
415 s = s' & |
396 s = s' & |
416 |
397 |
417 *) |
398 *) |
418 |
399 |
419 |
400 |
420 (*thm bv_raw.simps*) |
401 |
421 |
402 text {* weirdo example from Peter Sewell's bestiary *} |
422 (* example 3 from Peter Sewell's bestiary *) |
403 |
423 nominal_datatype exp = |
404 nominal_datatype weird = |
424 VarP "name" |
405 WBind x::"name" y::"name" p1::"weird" p2::"weird" p3::"weird" |
425 | AppP "exp" "exp" |
406 bind x in p1, bind x in p2, bind y in p2, bind y in p3 |
426 | LamP x::"name" e::"exp" bind x in e |
407 | WV "name" |
427 | LetP x::"name" p::"pat3" e1::"exp" e2::"exp" bind x in e2, bind "bp' p" in e1 |
408 | WP "weird" "weird" |
428 and pat3 = |
409 |
429 PVar "name" |
410 thm permute_weird_raw.simps[no_vars] |
430 | PUnit |
411 thm alpha_weird_raw.intros[no_vars] |
431 | PPair "pat3" "pat3" |
412 thm fv_weird_raw.simps[no_vars] |
432 binder |
413 |
433 bp' :: "pat3 \<Rightarrow> atom set" |
414 (* example 6 from Terms.thy *) |
434 where |
415 |
435 "bp' (PVar x) = {atom x}" |
416 (* BV is not respectful, needs to fail*) |
436 | "bp' (PUnit) = {}" |
417 nominal_datatype trm6 = |
437 | "bp' (PPair p1 p2) = bp' p1 \<union> bp' p2" |
418 Vr6 "name" |
438 thm alpha_exp_raw_alpha_pat3_raw_alpha_bp'_raw.intros |
419 | Lm6 x::"name" t::"trm6" bind x in t |
439 |
420 | Lt6 left::"trm6" right::"trm6" bind "bv6 left" in right |
440 (* example 6 from Peter Sewell's bestiary *) |
421 binder |
441 nominal_datatype exp6 = |
422 bv6 |
442 EVar name |
423 where |
443 | EPair exp6 exp6 |
424 "bv6 (Vr6 n) = {}" |
444 | ELetRec x::name p::pat6 e1::exp6 e2::exp6 bind x in e1, bind x in e2, bind "bp6 p" in e1 |
425 | "bv6 (Lm6 n t) = {atom n} \<union> bv6 t" |
445 and pat6 = |
426 | "bv6 (Lt6 l r) = bv6 l \<union> bv6 r" |
446 PVar' name |
427 (* example 7 from Terms.thy *) |
447 | PUnit' |
428 |
448 | PPair' pat6 pat6 |
429 (* BV is not respectful, needs to fail*) |
449 binder |
430 nominal_datatype trm7 = |
450 bp6 :: "pat6 \<Rightarrow> atom set" |
431 Vr7 "name" |
451 where |
432 | Lm7 l::"name" r::"trm7" bind l in r |
452 "bp6 (PVar' x) = {atom x}" |
433 | Lt7 l::"trm7" r::"trm7" bind "bv7 l" in r |
453 | "bp6 (PUnit') = {}" |
434 binder |
454 | "bp6 (PPair' p1 p2) = bp6 p1 \<union> bp6 p2" |
435 bv7 |
455 thm alpha_exp6_raw_alpha_pat6_raw_alpha_bp6_raw.intros |
436 where |
456 |
437 "bv7 (Vr7 n) = {atom n}" |
457 (* example 7 from Peter Sewell's bestiary *) |
438 | "bv7 (Lm7 n t) = bv7 t - {atom n}" |
458 nominal_datatype exp7 = |
439 | "bv7 (Lt7 l r) = bv7 l \<union> bv7 r" |
459 EVar name |
440 |
460 | EUnit |
441 (* example 8 from Terms.thy *) |
461 | EPair exp7 exp7 |
442 |
462 | ELetRec l::lrbs e::exp7 bind "b7s l" in e, bind "b7s l" in l |
443 (* Binding in a term under a bn, needs to fail *) |
463 and lrb = |
444 nominal_datatype foo8 = |
464 Assign name exp7 |
445 Foo0 "name" |
465 and lrbs = |
446 | Foo1 b::"bar8" f::"foo8" bind "bv8 b" in f --"check fo error if this is called foo" |
466 Single lrb |
447 and bar8 = |
467 | More lrb lrbs |
448 Bar0 "name" |
468 binder |
449 | Bar1 "name" s::"name" b::"bar8" bind s in b |
469 b7 :: "lrb \<Rightarrow> atom set" and |
450 binder |
470 b7s :: "lrbs \<Rightarrow> atom set" |
451 bv8 |
471 where |
452 where |
472 "b7 (Assign x e) = {atom x}" |
453 "bv8 (Bar0 x) = {}" |
473 | "b7s (Single a) = b7 a" |
454 | "bv8 (Bar1 v x b) = {atom v}" |
474 | "b7s (More a as) = (b7 a) \<union> (b7s as)" |
455 |
475 thm alpha_exp7_raw_alpha_lrb_raw_alpha_lrbs_raw.intros |
456 (* example 9 from Terms.thy *) |
476 |
457 |
477 (* example 8 from Peter Sewell's bestiary *) |
458 (* BV is not respectful, needs to fail*) |
478 nominal_datatype exp8 = |
459 nominal_datatype lam9 = |
479 EVar name |
460 Var9 "name" |
480 | EUnit |
461 | Lam9 n::"name" l::"lam9" bind n in l |
481 | EPair exp8 exp8 |
462 and bla9 = |
482 | ELetRec l::lrbs8 e::exp8 bind "b_lrbs8 l" in e, bind "b_lrbs8 l" in l |
463 Bla9 f::"lam9" s::"lam9" bind "bv9 f" in s |
483 and fnclause = |
464 binder |
484 K x::name p::pat8 e::exp8 bind "b_pat p" in e |
465 bv9 |
485 and fnclauses = |
466 where |
486 S fnclause |
467 "bv9 (Var9 x) = {}" |
487 | ORs fnclause fnclauses |
468 | "bv9 (Lam9 x b) = {atom x}" |
488 and lrb8 = |
469 |
489 Clause fnclauses |
470 |
490 and lrbs8 = |
471 (* Type schemes with separate datatypes *) |
491 Single lrb8 |
472 nominal_datatype t = |
492 | More lrb8 lrbs8 |
473 Var "name" |
493 and pat8 = |
474 | Fun "t" "t" |
494 PVar name |
475 |
495 | PUnit |
476 nominal_datatype tyS = |
496 | PPair pat8 pat8 |
477 All xs::"name list" ty::"t_raw" bind xs in ty |
497 binder |
|
498 b_lrbs8 :: "lrbs8 \<Rightarrow> atom set" and |
|
499 b_pat :: "pat8 \<Rightarrow> atom set" and |
|
500 b_fnclauses :: "fnclauses \<Rightarrow> atom set" and |
|
501 b_fnclause :: "fnclause \<Rightarrow> atom set" and |
|
502 b_lrb8 :: "lrb8 \<Rightarrow> atom set" |
|
503 where |
|
504 "b_lrbs8 (Single l) = b_lrb8 l" |
|
505 | "b_lrbs8 (More l ls) = b_lrb8 l \<union> b_lrbs8 ls" |
|
506 | "b_pat (PVar x) = {atom x}" |
|
507 | "b_pat (PUnit) = {}" |
|
508 | "b_pat (PPair p1 p2) = b_pat p1 \<union> b_pat p2" |
|
509 | "b_fnclauses (S fc) = (b_fnclause fc)" |
|
510 | "b_fnclauses (ORs fc fcs) = (b_fnclause fc) \<union> (b_fnclauses fcs)" |
|
511 | "b_lrb8 (Clause fcs) = (b_fnclauses fcs)" |
|
512 | "b_fnclause (K x pat exp8) = {atom x}" |
|
513 thm alpha_exp8_raw_alpha_fnclause_raw_alpha_fnclauses_raw_alpha_lrb8_raw_alpha_lrbs8_raw_alpha_pat8_raw.intros |
|
514 |
478 |
515 |
479 |
516 |
480 |
517 |
481 |
518 (* example 9 from Peter Sewell's bestiary *) |
482 (* example 9 from Peter Sewell's bestiary *) |