21 |
21 |
22 datatype arity_literal = |
22 datatype arity_literal = |
23 TConsLit of name * name * name list | |
23 TConsLit of name * name * name list | |
24 TVarLit of name * name |
24 TVarLit of name * name |
25 |
25 |
26 datatype arity_clause = |
26 type arity_clause = |
27 ArityClause of |
27 {name: string, |
28 {name: string, |
28 prem_lits: arity_literal list, |
29 prem_lits: arity_literal list, |
29 concl_lits: arity_literal} |
30 concl_lits: arity_literal} |
30 |
31 |
31 type class_rel_clause = |
32 datatype class_rel_clause = |
32 {name: string, |
33 ClassRelClause of {name: string, subclass: name, superclass: name} |
33 subclass: name, |
|
34 superclass: name} |
34 |
35 |
35 datatype combterm = |
36 datatype combterm = |
36 CombConst of name * typ * typ list | |
37 CombConst of name * typ * typ list | |
37 CombVar of name * typ | |
38 CombVar of name * typ | |
38 CombApp of combterm * combterm |
39 CombApp of combterm * combterm |
339 | pack_sort (tvar, "HOL.type" :: srt) = |
340 | pack_sort (tvar, "HOL.type" :: srt) = |
340 pack_sort (tvar, srt) (* IGNORE sort "type" *) |
341 pack_sort (tvar, srt) (* IGNORE sort "type" *) |
341 | pack_sort (tvar, cls :: srt) = |
342 | pack_sort (tvar, cls :: srt) = |
342 (`make_type_class cls, `I tvar) :: pack_sort (tvar, srt) |
343 (`make_type_class cls, `I tvar) :: pack_sort (tvar, srt) |
343 |
344 |
344 datatype arity_clause = |
345 type arity_clause = |
345 ArityClause of |
346 {name: string, |
346 {name: string, |
347 prem_lits: arity_literal list, |
347 prem_lits: arity_literal list, |
348 concl_lits: arity_literal} |
348 concl_lits: arity_literal} |
|
349 |
349 |
350 (* Arity of type constructor "tcon :: (arg1, ..., argN) res" *) |
350 (* Arity of type constructor "tcon :: (arg1, ..., argN) res" *) |
351 fun make_axiom_arity_clause (tcons, name, (cls, args)) = |
351 fun make_axiom_arity_clause (tcons, name, (cls, args)) = |
352 let |
352 let |
353 val tvars = gen_TVars (length args) |
353 val tvars = gen_TVars (length args) |
354 val tvars_srts = ListPair.zip (tvars, args) |
354 val tvars_srts = ListPair.zip (tvars, args) |
355 in |
355 in |
356 ArityClause {name = name, |
356 {name = name, |
357 prem_lits = map TVarLit (union_all (map pack_sort tvars_srts)), |
357 prem_lits = map TVarLit (union_all (map pack_sort tvars_srts)), |
358 concl_lits = TConsLit (`make_type_class cls, |
358 concl_lits = TConsLit (`make_type_class cls, |
359 `make_fixed_type_const tcons, |
359 `make_fixed_type_const tcons, |
360 tvars ~~ tvars)} |
360 tvars ~~ tvars)} |
361 end |
361 end |
362 |
362 |
363 fun arity_clause _ _ (_, []) = [] |
363 fun arity_clause _ _ (_, []) = [] |
364 | arity_clause seen n (tcons, ("HOL.type",_)::ars) = (*ignore*) |
364 | arity_clause seen n (tcons, ("HOL.type",_)::ars) = (*ignore*) |
365 arity_clause seen n (tcons,ars) |
365 arity_clause seen n (tcons,ars) |
399 iter_type_class_pairs thy tycons ##> multi_arity_clause |
399 iter_type_class_pairs thy tycons ##> multi_arity_clause |
400 |
400 |
401 |
401 |
402 (** Isabelle class relations **) |
402 (** Isabelle class relations **) |
403 |
403 |
404 datatype class_rel_clause = |
404 type class_rel_clause = |
405 ClassRelClause of {name: string, subclass: name, superclass: name} |
405 {name: string, |
|
406 subclass: name, |
|
407 superclass: name} |
406 |
408 |
407 (*Generate all pairs (sub,super) such that sub is a proper subclass of super in theory thy.*) |
409 (*Generate all pairs (sub,super) such that sub is a proper subclass of super in theory thy.*) |
408 fun class_pairs _ [] _ = [] |
410 fun class_pairs _ [] _ = [] |
409 | class_pairs thy subs supers = |
411 | class_pairs thy subs supers = |
410 let |
412 let |
412 fun add_super sub super = class_less (sub, super) ? cons (sub, super) |
414 fun add_super sub super = class_less (sub, super) ? cons (sub, super) |
413 fun add_supers sub = fold (add_super sub) supers |
415 fun add_supers sub = fold (add_super sub) supers |
414 in fold add_supers subs [] end |
416 in fold add_supers subs [] end |
415 |
417 |
416 fun make_class_rel_clause (sub,super) = |
418 fun make_class_rel_clause (sub,super) = |
417 ClassRelClause {name = sub ^ "_" ^ super, |
419 {name = sub ^ "_" ^ super, |
418 subclass = `make_type_class sub, |
420 subclass = `make_type_class sub, |
419 superclass = `make_type_class super} |
421 superclass = `make_type_class super} |
420 |
422 |
421 fun make_class_rel_clauses thy subs supers = |
423 fun make_class_rel_clauses thy subs supers = |
422 map make_class_rel_clause (class_pairs thy subs supers); |
424 map make_class_rel_clause (class_pairs thy subs supers); |
423 |
425 |
424 datatype combterm = |
426 datatype combterm = |
1459 Intro => intro_info |
1461 Intro => intro_info |
1460 | Elim => elim_info |
1462 | Elim => elim_info |
1461 | Simp => simp_info |
1463 | Simp => simp_info |
1462 | _ => NONE) |
1464 | _ => NONE) |
1463 |
1465 |
1464 fun formula_line_for_class_rel_clause |
1466 fun formula_line_for_class_rel_clause ({name, subclass, superclass, ...} |
1465 (ClassRelClause {name, subclass, superclass, ...}) = |
1467 : class_rel_clause) = |
1466 let val ty_arg = ATerm (`I "T", []) in |
1468 let val ty_arg = ATerm (`I "T", []) in |
1467 Formula (class_rel_clause_prefix ^ ascii_of name, Axiom, |
1469 Formula (class_rel_clause_prefix ^ ascii_of name, Axiom, |
1468 AConn (AImplies, [AAtom (ATerm (subclass, [ty_arg])), |
1470 AConn (AImplies, [AAtom (ATerm (subclass, [ty_arg])), |
1469 AAtom (ATerm (superclass, [ty_arg]))]) |
1471 AAtom (ATerm (superclass, [ty_arg]))]) |
1470 |> close_formula_universally, intro_info, NONE) |
1472 |> close_formula_universally, intro_info, NONE) |
1473 fun fo_literal_from_arity_literal (TConsLit (c, t, args)) = |
1475 fun fo_literal_from_arity_literal (TConsLit (c, t, args)) = |
1474 (true, ATerm (c, [ATerm (t, map (fn arg => ATerm (arg, [])) args)])) |
1476 (true, ATerm (c, [ATerm (t, map (fn arg => ATerm (arg, [])) args)])) |
1475 | fo_literal_from_arity_literal (TVarLit (c, sort)) = |
1477 | fo_literal_from_arity_literal (TVarLit (c, sort)) = |
1476 (false, ATerm (c, [ATerm (sort, [])])) |
1478 (false, ATerm (c, [ATerm (sort, [])])) |
1477 |
1479 |
1478 fun formula_line_for_arity_clause |
1480 fun formula_line_for_arity_clause ({name, prem_lits, concl_lits, ...} |
1479 (ArityClause {name, prem_lits, concl_lits, ...}) = |
1481 : arity_clause) = |
1480 Formula (arity_clause_prefix ^ ascii_of name, Axiom, |
1482 Formula (arity_clause_prefix ^ ascii_of name, Axiom, |
1481 mk_ahorn (map (formula_from_fo_literal o apfst not |
1483 mk_ahorn (map (formula_from_fo_literal o apfst not |
1482 o fo_literal_from_arity_literal) prem_lits) |
1484 o fo_literal_from_arity_literal) prem_lits) |
1483 (formula_from_fo_literal |
1485 (formula_from_fo_literal |
1484 (fo_literal_from_arity_literal concl_lits)) |
1486 (fo_literal_from_arity_literal concl_lits)) |