# HG changeset patch # User haftmann # Date 1196352506 -3600 # Node ID 9200b36280c012a012c4b471282b88a899231fba # Parent 845883bd3a6bb4bf1c28261ce1476695d9856f02 instance command as rudimentary class target diff -r 845883bd3a6b -r 9200b36280c0 NEWS --- a/NEWS Thu Nov 29 07:55:46 2007 +0100 +++ b/NEWS Thu Nov 29 17:08:26 2007 +0100 @@ -4,6 +4,14 @@ New in this Isabelle version ---------------------------- +*** Pure *** + +* Command "instance" now takes list of definitions in the same +manner as the "definition" command. Most notably, object equality is now +possible. Type inference is more canonical than it used to be. +INCOMPATIBILITY: in some cases explicit type annotations are required. + + *** HOL *** * Constant "card" now with authentic syntax. diff -r 845883bd3a6b -r 9200b36280c0 src/HOL/Complex/Complex.thy --- a/src/HOL/Complex/Complex.thy Thu Nov 29 07:55:46 2007 +0100 +++ b/src/HOL/Complex/Complex.thy Thu Nov 29 17:08:26 2007 +0100 @@ -45,7 +45,7 @@ complex_minus_def: "- x \ Complex (- Re x) (- Im x)" complex_diff_def: - "x - y \ x + - y" .. + "x - (y\complex) \ x + - y" .. lemma Complex_eq_0 [simp]: "(Complex a b = 0) = (a = 0 \ b = 0)" by (simp add: complex_zero_def) @@ -116,7 +116,7 @@ "inverse x \ Complex (Re x / ((Re x)\ + (Im x)\)) (- Im x / ((Re x)\ + (Im x)\))" complex_divide_def: - "x / y \ x * inverse y" .. + "x / (y\complex) \ x * inverse y" .. lemma Complex_eq_1 [simp]: "(Complex a b = 1) = (a = 1 \ b = 0)" by (simp add: complex_one_def) @@ -195,7 +195,7 @@ instance complex :: number complex_number_of_def: - "number_of w \ of_int w" .. + "number_of w \ of_int w \ complex" .. instance complex :: number_ring by (intro_classes, simp only: complex_number_of_def) @@ -213,10 +213,10 @@ by (cases z rule: int_diff_cases) simp lemma complex_Re_number_of [simp]: "Re (number_of v) = number_of v" -unfolding number_ring_class.axioms by (rule complex_Re_of_int) +unfolding number_of_eq by (rule complex_Re_of_int) lemma complex_Im_number_of [simp]: "Im (number_of v) = 0" -unfolding number_ring_class.axioms by (rule complex_Im_of_int) +unfolding number_of_eq by (rule complex_Im_of_int) lemma Complex_eq_number_of [simp]: "(Complex a b = number_of w) = (a = number_of w \ b = 0)" diff -r 845883bd3a6b -r 9200b36280c0 src/HOL/Finite_Set.thy --- a/src/HOL/Finite_Set.thy Thu Nov 29 07:55:46 2007 +0100 +++ b/src/HOL/Finite_Set.thy Thu Nov 29 17:08:26 2007 +0100 @@ -2689,7 +2689,7 @@ lemmas [code func] = univ_bool instance * :: (finite, finite) finite - "itself \ TYPE('a\finite)" + "itself \ TYPE('a \ 'b)" proof show "finite (UNIV :: ('a \ 'b) set)" proof (rule finite_Prod_UNIV) @@ -2703,7 +2703,7 @@ unfolding UNIV_Times_UNIV .. instance "+" :: (finite, finite) finite - "itself \ TYPE('a\finite + 'b\finite)" + "itself \ TYPE('a + 'b)" proof have a: "finite (UNIV :: 'a set)" by (rule finite) have b: "finite (UNIV :: 'b set)" by (rule finite) @@ -2717,7 +2717,7 @@ unfolding UNIV_Plus_UNIV .. instance set :: (finite) finite - "itself \ TYPE('a\finite set)" + "itself \ TYPE('a set)" proof have "finite (UNIV :: 'a set)" by (rule finite) hence "finite (Pow (UNIV :: 'a set))" @@ -2732,7 +2732,7 @@ by (rule inj_onI, auto simp add: expand_set_eq expand_fun_eq) instance "fun" :: (finite, finite) finite - "itself \ TYPE('a\finite \ 'b\finite)" + "itself \ TYPE('a \ 'b)" proof show "finite (UNIV :: ('a => 'b) set)" proof (rule finite_imageD) diff -r 845883bd3a6b -r 9200b36280c0 src/HOL/IntDef.thy --- a/src/HOL/IntDef.thy Thu Nov 29 07:55:46 2007 +0100 +++ b/src/HOL/IntDef.thy Thu Nov 29 17:08:26 2007 +0100 @@ -36,7 +36,7 @@ instance int :: minus minus_int_def: "- z \ Abs_Integ (\(x, y) \ Rep_Integ z. intrel `` {(y, x)})" - diff_int_def: "z - w \ z + (-w)" .. + diff_int_def: "z - w \ z + (-w \ int)" .. instance int :: times mult_int_def: "z * w \ Abs_Integ @@ -46,7 +46,7 @@ instance int :: ord le_int_def: "z \ w \ \x y u v. x+v \ u+y \ (x, y) \ Rep_Integ z \ (u, v) \ Rep_Integ w" - less_int_def: "z < w \ z \ w \ z \ w" .. + less_int_def: "(z\int) < w \ z \ w \ z \ w" .. lemmas [code func del] = Zero_int_def One_int_def add_int_def minus_int_def mult_int_def le_int_def less_int_def @@ -218,8 +218,8 @@ zsgn_def: "sgn(i\int) \ (if i=0 then 0 else if 0 min" - "sup \ max" + "inf \ int \ int \ int \ min" + "sup \ int \ int \ int \ max" by intro_classes (auto simp add: inf_int_def sup_int_def min_max.sup_inf_distrib1) diff -r 845883bd3a6b -r 9200b36280c0 src/HOL/Library/Char_ord.thy --- a/src/HOL/Library/Char_ord.thy Thu Nov 29 07:55:46 2007 +0100 +++ b/src/HOL/Library/Char_ord.thy Thu Nov 29 17:08:26 2007 +0100 @@ -39,8 +39,8 @@ qed instance nibble :: distrib_lattice - "inf \ min" - "sup \ max" + "(inf \ nibble \ _) = min" + "(sup \ nibble \ _) = max" by default (auto simp add: inf_nibble_def sup_nibble_def min_max.sup_inf_distrib1) @@ -54,8 +54,8 @@ lemmas [code func del] = char_less_eq_def char_less_def instance char :: distrib_lattice - "inf \ min" - "sup \ max" + "(inf \ char \ _) = min" + "(sup \ char \ _) = max" by default (auto simp add: inf_char_def sup_char_def min_max.sup_inf_distrib1) diff -r 845883bd3a6b -r 9200b36280c0 src/HOL/Library/Code_Index.thy --- a/src/HOL/Library/Code_Index.thy Thu Nov 29 07:55:46 2007 +0100 +++ b/src/HOL/Library/Code_Index.thy Thu Nov 29 17:08:26 2007 +0100 @@ -143,7 +143,7 @@ by simp instance index :: abs - "\k\ \ if k < 0 then -k else k" .. + "\k\index\ \ if k < 0 then -k else k" .. lemma index_of_int [code func]: "index_of_int k = (if k = 0 then 0 diff -r 845883bd3a6b -r 9200b36280c0 src/HOL/Library/Eval.thy --- a/src/HOL/Library/Eval.thy Thu Nov 29 07:55:46 2007 +0100 +++ b/src/HOL/Library/Eval.thy Thu Nov 29 17:08:26 2007 +0100 @@ -35,16 +35,16 @@ *} instance "prop" :: typ_of - "typ_of T \ STR ''prop'' {\} []" .. + "typ_of (T\prop itself) \ STR ''prop'' {\} []" .. instance itself :: (typ_of) typ_of - "typ_of T \ STR ''itself'' {\} [typ_of TYPE('a\typ_of)]" .. + "typ_of (T\'a itself itself) \ STR ''itself'' {\} [typ_of TYPE('a\typ_of)]" .. instance set :: (typ_of) typ_of - "typ_of T \ STR ''set'' {\} [typ_of TYPE('a\typ_of)]" .. + "typ_of (T\'a set itself) \ STR ''set'' {\} [typ_of TYPE('a\typ_of)]" .. instance int :: typ_of - "typ_of T \ STR ''IntDef.int'' {\} []" .. + "typ_of (T\int itself) \ STR ''IntDef.int'' {\} []" .. setup {* let diff -r 845883bd3a6b -r 9200b36280c0 src/HOL/Library/List_lexord.thy --- a/src/HOL/Library/List_lexord.thy Thu Nov 29 07:55:46 2007 +0100 +++ b/src/HOL/Library/List_lexord.thy Thu Nov 29 17:08:26 2007 +0100 @@ -10,13 +10,11 @@ begin instance list :: (ord) ord - list_le_def: "(xs::('a::ord) list) \ ys \ (xs < ys \ xs = ys)" - list_less_def: "(xs::('a::ord) list) < ys \ (xs, ys) \ lexord {(u,v). u < v}" .. - -lemmas list_ord_defs [code func del] = list_less_def list_le_def + list_less_def [code func del]: "(xs::('a::ord) list) < ys \ (xs, ys) \ lexord {(u,v). u < v}" + list_le_def [code func del]: "(xs::('a::ord) list) \ ys \ (xs < ys \ xs = ys)" .. instance list :: (order) order - apply (intro_classes, unfold list_ord_defs) + apply (intro_classes, unfold list_less_def list_le_def) apply safe apply (rule_tac r1 = "{(a::'a,b). a < b}" in lexord_irreflexive [THEN notE]) apply simp @@ -35,13 +33,11 @@ done instance list :: (linorder) distrib_lattice - "inf \ min" - "sup \ max" + [code func del]: "(inf \ 'a list \ _) = min" + [code func del]: "(sup \ 'a list \ _) = max" by intro_classes (auto simp add: inf_list_def sup_list_def min_max.sup_inf_distrib1) -lemmas [code func del] = inf_list_def sup_list_def - lemma not_less_Nil [simp]: "\ (x < [])" by (unfold list_less_def) simp @@ -52,13 +48,13 @@ by (unfold list_less_def) simp lemma le_Nil [simp]: "x \ [] \ x = []" - by (unfold list_ord_defs, cases x) auto + by (unfold list_le_def, cases x) auto lemma Nil_le_Cons [simp]: "[] \ x" - by (unfold list_ord_defs, cases x) auto + by (unfold list_le_def, cases x) auto lemma Cons_le_Cons [simp]: "a # x \ b # y \ a < b \ a = b \ x \ y" - by (unfold list_ord_defs) auto + by (unfold list_le_def) auto lemma less_code [code func]: "xs < ([]\'a\{eq, order} list) \ False" diff -r 845883bd3a6b -r 9200b36280c0 src/HOL/Library/Parity.thy --- a/src/HOL/Library/Parity.thy Thu Nov 29 07:55:46 2007 +0100 +++ b/src/HOL/Library/Parity.thy Thu Nov 29 17:08:26 2007 +0100 @@ -17,7 +17,7 @@ "odd x \ \ even x" instance int :: even_odd - even_def[presburger]: "even x \ x mod 2 = 0" .. + even_def[presburger]: "even x \ (x\int) mod 2 = 0" .. instance nat :: even_odd even_nat_def[presburger]: "even x \ even (int x)" .. diff -r 845883bd3a6b -r 9200b36280c0 src/HOL/Library/Product_ord.thy --- a/src/HOL/Library/Product_ord.thy Thu Nov 29 07:55:46 2007 +0100 +++ b/src/HOL/Library/Product_ord.thy Thu Nov 29 17:08:26 2007 +0100 @@ -10,30 +10,28 @@ begin instance "*" :: (ord, ord) ord - prod_le_def: "(x \ y) \ (fst x < fst y) \ (fst x = fst y \ snd x \ snd y)" - prod_less_def: "(x < y) \ (fst x < fst y) \ (fst x = fst y \ snd x < snd y)" .. - -lemmas prod_ord_defs [code func del] = prod_less_def prod_le_def + prod_le_def [code func del]: "x \ y \ fst x < fst y \ fst x = fst y \ snd x \ snd y" + prod_less_def [code func del]: "x < y \ fst x < fst y \ fst x = fst y \ snd x < snd y" .. lemma [code func]: "(x1\'a\{ord, eq}, y1) \ (x2, y2) \ x1 < x2 \ x1 = x2 \ y1 \ y2" "(x1\'a\{ord, eq}, y1) < (x2, y2) \ x1 < x2 \ x1 = x2 \ y1 < y2" - unfolding prod_ord_defs by simp_all + unfolding prod_le_def prod_less_def by simp_all lemma [code]: "(x1, y1) \ (x2, y2) \ x1 < x2 \ x1 = x2 \ y1 \ y2" "(x1, y1) < (x2, y2) \ x1 < x2 \ x1 = x2 \ y1 < y2" - unfolding prod_ord_defs by simp_all + unfolding prod_le_def prod_less_def by simp_all instance * :: (order, order) order - by default (auto simp: prod_ord_defs intro: order_less_trans) + by default (auto simp: prod_le_def prod_less_def intro: order_less_trans) instance * :: (linorder, linorder) linorder by default (auto simp: prod_le_def) instance * :: (linorder, linorder) distrib_lattice - inf_prod_def: "inf \ min" - sup_prod_def: "sup \ max" + inf_prod_def: "(inf \ 'a \ 'b \ _ \ _) = min" + sup_prod_def: "(sup \ 'a \ 'b \ _ \ _) = max" by intro_classes (auto simp add: inf_prod_def sup_prod_def min_max.sup_inf_distrib1) diff -r 845883bd3a6b -r 9200b36280c0 src/HOL/List.thy --- a/src/HOL/List.thy Thu Nov 29 07:55:46 2007 +0100 +++ b/src/HOL/List.thy Thu Nov 29 17:08:26 2007 +0100 @@ -2691,7 +2691,7 @@ text{* The integers are an instance of the above class: *} instance int:: finite_intvl_succ - successor_int_def: "successor == (%i. i+1)" + successor_int_def: "successor == (%i\int. i+1)" by intro_classes (simp_all add: successor_int_def) text{* Now @{term"[i..j::int]"} is defined for integers. *} diff -r 845883bd3a6b -r 9200b36280c0 src/HOL/Matrix/Matrix.thy --- a/src/HOL/Matrix/Matrix.thy Thu Nov 29 07:55:46 2007 +0100 +++ b/src/HOL/Matrix/Matrix.thy Thu Nov 29 17:08:26 2007 +0100 @@ -23,7 +23,7 @@ times_matrix_def: "A * B \ mult_matrix (op *) (op +) A B" .. instance matrix :: (lordered_ab_group_add) abs - abs_matrix_def: "abs A \ sup A (- A)" .. + abs_matrix_def: "abs (A \ 'a matrix) \ sup A (- A)" .. instance matrix :: (lordered_ab_group_add) lordered_ab_group_add_meet proof diff -r 845883bd3a6b -r 9200b36280c0 src/HOL/Matrix/MatrixGeneral.thy --- a/src/HOL/Matrix/MatrixGeneral.thy Thu Nov 29 07:55:46 2007 +0100 +++ b/src/HOL/Matrix/MatrixGeneral.thy Thu Nov 29 17:08:26 2007 +0100 @@ -1281,7 +1281,7 @@ instance matrix :: ("{ord, zero}") ord le_matrix_def: "A \ B \ \j i. Rep_matrix A j i \ Rep_matrix B j i" - less_def: "A < B \ A \ B \ A \ B" .. + less_def: "A < (B\'a matrix) \ A \ B \ A \ B" .. instance matrix :: ("{order, zero}") order apply intro_classes diff -r 845883bd3a6b -r 9200b36280c0 src/HOL/Nat.thy --- a/src/HOL/Nat.thy Thu Nov 29 07:55:46 2007 +0100 +++ b/src/HOL/Nat.thy Thu Nov 29 17:08:26 2007 +0100 @@ -1488,8 +1488,8 @@ text {* the lattice order on @{typ nat} *} instance nat :: distrib_lattice - "inf \ min" - "sup \ max" + "inf \ nat \ nat \ nat \ min" + "sup \ nat \ nat \ nat \ max" by intro_classes (simp_all add: inf_nat_def sup_nat_def) diff -r 845883bd3a6b -r 9200b36280c0 src/HOL/Numeral.thy --- a/src/HOL/Numeral.thy Thu Nov 29 07:55:46 2007 +0100 +++ b/src/HOL/Numeral.thy Thu Nov 29 17:08:26 2007 +0100 @@ -203,16 +203,15 @@ unfolding numeral_simps int_distrib by simp - subsection {* Converting Numerals to Rings: @{term number_of} *} -axclass number_ring \ number, comm_ring_1 - number_of_eq: "number_of k = of_int k" +class number_ring = number + comm_ring_1 + + assumes number_of_eq: "number_of k = of_int k" text {* self-embedding of the integers *} instance int :: number_ring - int_number_of_def: "number_of w \ of_int w" + int_number_of_def: "number_of w \ of_int w \ int" by intro_classes (simp only: int_number_of_def) lemmas [code func del] = int_number_of_def diff -r 845883bd3a6b -r 9200b36280c0 src/HOL/Orderings.thy --- a/src/HOL/Orderings.thy Thu Nov 29 07:55:46 2007 +0100 +++ b/src/HOL/Orderings.thy Thu Nov 29 17:08:26 2007 +0100 @@ -930,7 +930,7 @@ instance bool :: order le_bool_def: "P \ Q \ P \ Q" - less_bool_def: "P < Q \ P \ Q \ P \ Q" + less_bool_def: "(P\bool) < Q \ P \ Q \ P \ Q" by intro_classes (auto simp add: le_bool_def less_bool_def) lemmas [code func del] = le_bool_def less_bool_def @@ -968,7 +968,7 @@ instance "fun" :: (type, ord) ord le_fun_def: "f \ g \ \x. f x \ g x" - less_fun_def: "f < g \ f \ g \ f \ g" .. + less_fun_def: "(f\'a \ 'b) < g \ f \ g \ f \ g" .. lemmas [code func del] = le_fun_def less_fun_def diff -r 845883bd3a6b -r 9200b36280c0 src/HOL/Real/PReal.thy --- a/src/HOL/Real/PReal.thy Thu Nov 29 07:55:46 2007 +0100 +++ b/src/HOL/Real/PReal.thy Thu Nov 29 17:08:26 2007 +0100 @@ -212,8 +212,8 @@ by intro_classes (rule preal_le_linear) instance preal :: distrib_lattice - "inf \ min" - "sup \ max" + "inf \ preal \ preal \ preal \ min" + "sup \ preal \ preal \ preal \ max" by intro_classes (auto simp add: inf_preal_def sup_preal_def min_max.sup_inf_distrib1) diff -r 845883bd3a6b -r 9200b36280c0 src/HOL/Real/Rational.thy --- a/src/HOL/Real/Rational.thy Thu Nov 29 07:55:46 2007 +0100 +++ b/src/HOL/Real/Rational.thy Thu Nov 29 17:08:26 2007 +0100 @@ -362,8 +362,8 @@ qed instance rat :: distrib_lattice - "inf r s \ min r s" - "sup r s \ max r s" + "inf \ rat \ rat \ rat \ min" + "sup \ rat \ rat \ rat \ max" by default (auto simp add: min_max.sup_inf_distrib1 inf_rat_def sup_rat_def) instance rat :: ordered_field diff -r 845883bd3a6b -r 9200b36280c0 src/HOL/Real/RealDef.thy --- a/src/HOL/Real/RealDef.thy Thu Nov 29 07:55:46 2007 +0100 +++ b/src/HOL/Real/RealDef.thy Thu Nov 29 17:08:26 2007 +0100 @@ -66,7 +66,7 @@ real_abs_def: "abs (r::real) == (if r < 0 then - r else r)" .. instance real :: sgn - real_sgn_def: "sgn x == (if x=0 then 0 else if 0 min x y" - "sup x y \ max x y" + "inf \ real \ real \ real \ min" + "sup \ real \ real \ real \ max" by default (auto simp add: inf_real_def sup_real_def min_max.sup_inf_distrib1) diff -r 845883bd3a6b -r 9200b36280c0 src/HOL/Set.thy --- a/src/HOL/Set.thy Thu Nov 29 07:55:46 2007 +0100 +++ b/src/HOL/Set.thy Thu Nov 29 17:08:26 2007 +0100 @@ -145,7 +145,7 @@ instance set :: (type) ord subset_def: "A \ B \ \x\A. x \ B" - psubset_def: "A < B \ A \ B \ A \ B" .. + psubset_def: "(A\'a set) < B \ A \ B \ A \ B" .. lemmas [code func del] = subset_def psubset_def abbreviation diff -r 845883bd3a6b -r 9200b36280c0 src/HOL/SizeChange/Graphs.thy --- a/src/HOL/SizeChange/Graphs.thy Thu Nov 29 07:55:46 2007 +0100 +++ b/src/HOL/SizeChange/Graphs.thy Thu Nov 29 17:08:26 2007 +0100 @@ -79,7 +79,7 @@ graph_leq_def: "G \ H \ dest_graph G \ dest_graph H" graph_less_def: "G < H \ dest_graph G \ dest_graph H" "inf G H \ Graph (dest_graph G \ dest_graph H)" - "sup G H \ G + H" + "sup (G \ ('a, 'b) graph) H \ G + H" Inf_graph_def: "Inf \ \Gs. Graph (\(dest_graph ` Gs))" Sup_graph_def: "Sup \ \Gs. Graph (\(dest_graph ` Gs))" proof @@ -195,10 +195,10 @@ "grpow 0 A = 1" | "grpow (Suc n) A = A * (grpow n A)" -instance graph :: (type, monoid_mult) +instance graph :: (type, monoid_mult) "{semiring_1,idem_add,recpower,star}" graph_pow_def: "A ^ n == grpow n A" - graph_star_def: "star G == (SUP n. G ^ n)" + graph_star_def: "star (G \ ('a, 'b) graph) == (SUP n. G ^ n)" proof fix a b c :: "('a, 'b) graph" diff -r 845883bd3a6b -r 9200b36280c0 src/HOL/Tools/datatype_codegen.ML --- a/src/HOL/Tools/datatype_codegen.ML Thu Nov 29 07:55:46 2007 +0100 +++ b/src/HOL/Tools/datatype_codegen.ML Thu Nov 29 17:08:26 2007 +0100 @@ -544,7 +544,7 @@ |> not (null arities) ? ( f arities css #-> (fn defs => - Class.prove_instance tac arities defs + Instance.prove_instance tac arities defs #-> (fn defs => after_qed arities css defs))) end; diff -r 845883bd3a6b -r 9200b36280c0 src/HOL/Tools/function_package/size.ML --- a/src/HOL/Tools/function_package/size.ML Thu Nov 29 07:55:46 2007 +0100 +++ b/src/HOL/Tools/function_package/size.ML Thu Nov 29 17:08:26 2007 +0100 @@ -38,7 +38,7 @@ val n = Sign.arity_number thy tyco; in thy - |> Class.prove_instance (Class.intro_classes_tac []) + |> Instance.prove_instance (Class.intro_classes_tac []) [(tyco, replicate n HOLogic.typeS, [HOLogic.class_size])] [] |> snd end diff -r 845883bd3a6b -r 9200b36280c0 src/HOL/ex/Classpackage.thy --- a/src/HOL/ex/Classpackage.thy Thu Nov 29 07:55:46 2007 +0100 +++ b/src/HOL/ex/Classpackage.thy Thu Nov 29 17:08:26 2007 +0100 @@ -13,14 +13,14 @@ assumes assoc: "x \ y \ z = x \ (y \ z)" instance nat :: semigroup - "m \ n \ m + n" + "m \ n \ (m\nat) + n" proof fix m n q :: nat from mult_nat_def show "m \ n \ q = m \ (n \ q)" by simp qed instance int :: semigroup - "k \ l \ k + l" + "k \ l \ (k\int) + l" proof fix k l j :: int from mult_int_def show "k \ l \ j = k \ (l \ j)" by simp @@ -47,8 +47,8 @@ assumes neutl: "\ \ x = x" instance nat :: monoidl and int :: monoidl - "\ \ 0" - "\ \ 0" + "\ \ (0\nat)" + "\ \ (0\int)" proof fix n :: nat from mult_nat_def one_nat_def show "\ \ n = n" by simp diff -r 845883bd3a6b -r 9200b36280c0 src/Pure/Isar/class.ML --- a/src/Pure/Isar/class.ML Thu Nov 29 07:55:46 2007 +0100 +++ b/src/Pure/Isar/class.ML Thu Nov 29 17:08:26 2007 +0100 @@ -57,16 +57,7 @@ (*old instance layer*) val instance_arity: (theory -> theory) -> arity list -> theory -> Proof.state - val instance: arity list -> ((bstring * Attrib.src list) * term) list - -> (thm list -> theory -> theory) - -> theory -> Proof.state - val instance_cmd: (bstring * xstring list * xstring) list - -> ((bstring * Attrib.src list) * xstring) list - -> (thm list -> theory -> theory) - -> theory -> Proof.state - val prove_instance: tactic -> arity list - -> ((bstring * Attrib.src list) * term) list - -> theory -> thm list * theory + val instance_arity_cmd: (bstring * xstring list * xstring) list -> theory -> Proof.state end; structure Class : CLASS = @@ -150,6 +141,8 @@ val instance_arity = gen_instance (Logic.mk_arities oo Sign.cert_arity) AxClass.add_arity; +val instance_arity_cmd = + gen_instance (Logic.mk_arities oo Sign.read_arity) AxClass.add_arity I; val classrel = gen_instance (single oo (Logic.mk_classrel oo AxClass.cert_classrel)) AxClass.add_classrel I o single; @@ -221,7 +214,7 @@ val SOME class = AxClass.class_of_param thy c; val SOME tyco = inst_tyco thy (c, ty); val name_inst = AxClass.instance_name (tyco, class) ^ "_inst"; - val c' = NameSpace.base c; + val c' = NameSpace.base c ^ "_" ^ NameSpace.base tyco; val ty' = Type.strip_sorts ty; in thy @@ -253,137 +246,6 @@ end; -(* legacy *) - -fun add_inst_def (class, tyco) (c, ty) thy = - let - val tyco_base = Sign.base_name tyco; - val name_inst = Sign.base_name class ^ "_" ^ tyco_base ^ "_inst"; - val c_inst_base = Sign.base_name c ^ "_" ^ tyco_base; - in - thy - |> Sign.sticky_prefix name_inst - |> Sign.declare_const [] (c_inst_base, ty, NoSyn) - |-> (fn const as Const (c_inst, _) => - PureThy.add_defs_i false - [((Thm.def_name c_inst_base, Logic.mk_equals (const, Const (c, ty))), [])] - #-> (fn [thm] => add_inst (c, tyco) (c_inst, Thm.symmetric thm))) - |> Sign.restore_naming thy - end; - -fun add_inst_def' (class, tyco) (c, ty) thy = - if case Symtab.lookup (fst (InstData.get thy)) c - of NONE => true - | SOME tab => is_none (Symtab.lookup tab tyco) - then add_inst_def (class, tyco) (c, Logic.unvarifyT ty) thy - else thy; - -fun add_def ((class, tyco), ((name, prop), atts)) thy = - let - val ((lhs as Const (c, ty), args), rhs) = - (apfst Term.strip_comb o Logic.dest_equals) prop; - in - thy - |> PureThy.add_defs_i true [((name, prop), map (Attrib.attribute_i thy) atts)] - |-> (fn [def] => add_inst_def (class, tyco) (c, ty) #> pair def) - end; - - -(** instances with implicit parameter handling **) - -local - -fun gen_read_def thy prep_att parse_prop ((raw_name, raw_atts), raw_t) = - let - val ctxt = ProofContext.init thy; - val t = parse_prop ctxt raw_t |> Syntax.check_prop ctxt; - val ((c, ty), _) = Sign.cert_def ctxt t; - val atts = map (prep_att thy) raw_atts; - val insts = Consts.typargs (Sign.consts_of thy) (c, ty); - val name = case raw_name - of "" => NONE - | _ => SOME raw_name; - in (c, (insts, ((name, t), atts))) end; - -fun read_def_cmd thy = gen_read_def thy Attrib.intern_src Syntax.parse_prop; -fun read_def thy = gen_read_def thy (K I) (K I); - -fun gen_instance prep_arity read_def do_proof raw_arities raw_defs after_qed theory = - let - val arities = map (prep_arity theory) raw_arities; - val _ = if null arities then error "At least one arity must be given" else (); - val _ = case (duplicates (op =) o map #1) arities - of [] => () - | dupl_tycos => error ("Type constructors occur more than once in arities: " - ^ commas_quote dupl_tycos); - fun get_consts_class tyco ty class = - let - val cs = (these o try (#params o AxClass.get_info theory)) class; - val subst_ty = map_type_tfree (K ty); - in - map (fn (c, ty) => (c, ((class, tyco), subst_ty ty))) cs - end; - fun get_consts_sort (tyco, asorts, sort) = - let - val ty = Type (tyco, map (fn (v, sort) => TVar ((v, 0), sort)) - (Name.names Name.context Name.aT asorts)) - in maps (get_consts_class tyco ty) (Sign.complete_sort theory sort) end; - val cs = maps get_consts_sort arities; - fun mk_typnorm thy (ty, ty_sc) = - case try (Sign.typ_match thy (Logic.varifyT ty_sc, ty)) Vartab.empty - of SOME env => SOME (Logic.varifyT #> Envir.typ_subst_TVars env #> Logic.unvarifyT) - | NONE => NONE; - fun read_defs defs cs thy_read = - let - fun read raw_def cs = - let - val (c, (inst, ((name_opt, t), atts))) = read_def thy_read raw_def; - val ty = Consts.instance (Sign.consts_of thy_read) (c, inst); - val ((class, tyco), ty') = case AList.lookup (op =) cs c - of NONE => error ("Illegal definition for constant " ^ quote c) - | SOME class_ty => class_ty; - val name = case name_opt - of NONE => Thm.def_name (Logic.name_arity (tyco, [], c)) - | SOME name => name; - val t' = case mk_typnorm thy_read (ty', ty) - of NONE => error ("Illegal definition for constant " ^ - quote (c ^ "::" ^ setmp show_sorts true - (Sign.string_of_typ thy_read) ty)) - | SOME norm => map_types norm t - in (((class, tyco), ((name, t'), atts)), AList.delete (op =) c cs) end; - in fold_map read defs cs end; - val (defs, other_cs) = read_defs raw_defs cs - (fold Sign.primitive_arity arities (Theory.copy theory)); - fun after_qed' cs defs = - fold Sign.add_const_constraint (map (apsnd SOME) cs) - #> after_qed defs; - in - theory - |> fold_map get_remove_global_constraint (map fst cs |> distinct (op =)) - ||>> fold_map add_def defs - ||> fold (fn (c, ((class, tyco), ty)) => add_inst_def' (class, tyco) (c, ty)) other_cs - |-> (fn (cs, defs) => do_proof (after_qed' cs defs) arities defs) - end; - -fun tactic_proof tac f arities defs = - fold (fn arity => AxClass.prove_arity arity tac) arities - #> f - #> pair defs; - -in - -val instance = gen_instance Sign.cert_arity read_def - (fn f => fn arities => fn defs => instance_arity f arities); -val instance_cmd = gen_instance Sign.read_arity read_def_cmd - (fn f => fn arities => fn defs => instance_arity f arities); -fun prove_instance tac arities defs = - gen_instance Sign.cert_arity read_def - (tactic_proof tac) arities defs (K I); - -end; (*local*) - - - (** class data **) datatype class_data = ClassData of { @@ -1008,7 +870,7 @@ fun check_improve (Const (c, ty)) = (case inst_tyco thy (c, ty) of SOME tyco => (case AList.lookup (op =) params (c, tyco) - of SOME (_, ty') => Type.typ_match tsig (ty, ty') + of SOME (_, ty') => perhaps (try (Type.typ_match tsig (ty, ty'))) | NONE => I) | NONE => I) | check_improve _ = I; @@ -1057,6 +919,7 @@ of [] => () | dupl_tycos => error ("Type constructors occur more than once in arities: " ^ commas_quote dupl_tycos); + val _ = map (map (the_class_data thy) o #3) arities; val ty_insts = map (fn (tyco, sorts, _) => (tyco, Type (tyco, map TFree (Name.names Name.context Name.aT sorts)))) arities; @@ -1064,12 +927,11 @@ fun type_name "*" = "prod" | type_name "+" = "sum" | type_name s = sanatize_name (NameSpace.base s); (*FIXME*) - fun get_param tyco sorts (param, (c, ty)) = - ((unoverload_const thy (c, ty), tyco), - (param ^ "_" ^ type_name tyco, - map_atyps (K (ty_inst tyco)) ty)); + fun get_param tyco sorts (param, (c, ty)) = if can (inst thy) (c, tyco) + then NONE else SOME ((unoverload_const thy (c, ty), tyco), + (param ^ "_" ^ type_name tyco, map_atyps (K (ty_inst tyco)) ty)); fun get_params (tyco, sorts, sort) = - map (get_param tyco sorts) (these_params thy sort) + map_filter (get_param tyco sorts) (these_params thy sort) val params = maps get_params arities; in thy @@ -1099,8 +961,8 @@ Proof.theorem_i NONE (after_qed o map the_single) (map (fn t => [(t, [])]) ts)); fun prove_instantiation_instance tac = gen_instantiation_instance (fn after_qed => - fn ts => fn lthy => after_qed (Goal.prove_multi lthy [] [] ts - (fn {context, ...} => tac context)) lthy) I; + fn ts => fn lthy => after_qed (map (fn t => Goal.prove lthy [] [] t + (fn {context, ...} => tac context)) ts) lthy) I; fun conclude_instantiation lthy = let @@ -1121,7 +983,7 @@ let val SOME class = AxClass.class_of_param thy c; val name_inst = AxClass.instance_name (tyco, class) ^ "_inst"; - val c' = NameSpace.base c; + val c' = NameSpace.base c ^ "_" ^ NameSpace.base tyco; val vs = Name.names Name.context Name.aT (replicate (Sign.arity_number thy tyco) []); val ty = map_atyps (fn _ => Type (tyco, map TFree vs)) ty0; in diff -r 845883bd3a6b -r 9200b36280c0 src/Pure/Isar/instance.ML --- a/src/Pure/Isar/instance.ML Thu Nov 29 07:55:46 2007 +0100 +++ b/src/Pure/Isar/instance.ML Thu Nov 29 17:08:26 2007 +0100 @@ -10,7 +10,6 @@ val instantiate: arity list -> (local_theory -> local_theory) -> (Proof.context -> tactic) -> theory -> theory val instance: arity list -> ((bstring * Attrib.src list) * term) list - -> (thm list -> theory -> theory) -> theory -> Proof.state val prove_instance: tactic -> arity list -> ((bstring * Attrib.src list) * term) list -> theory -> thm list * theory @@ -18,7 +17,6 @@ val instantiation_cmd: (xstring * sort * xstring) list -> theory -> local_theory val instance_cmd: (xstring * sort * xstring) list -> ((bstring * Attrib.src list) * xstring) list - -> (thm list -> theory -> theory) -> theory -> Proof.state end; @@ -35,8 +33,9 @@ #> LocalTheory.exit #> ProofContext.theory_of; -fun gen_instance prep_arity prep_attr parse_term do_proof raw_arities defs after_qed thy = +fun gen_instance prep_arity prep_attr parse_term do_proof do_proof' raw_arities defs thy = let + val arities = map (prep_arity thy) raw_arities; fun export_defs ctxt = let val ctxt_thy = ProofContext.init (ProofContext.theory_of ctxt); @@ -54,8 +53,9 @@ let val def' = (apsnd o apsnd) (Syntax.check_prop ctxt) def; in Specification.definition def' ctxt end; - val arities = map (prep_arity thy) raw_arities; - in + in if not (null defs) orelse forall (fn (_, _, sort) => + forall (Class.is_class thy) sort) arities + then thy |> TheoryTarget.instantiation arities |> `(fn ctxt => map (mk_def ctxt) defs) @@ -64,15 +64,21 @@ ||> LocalTheory.exit ||> ProofContext.theory_of ||> TheoryTarget.instantiation arities - |-> (fn defs => do_proof defs (LocalTheory.theory (after_qed defs))) + |-> (fn defs => do_proof defs) + else + thy + |> do_proof' arities end; val instance = gen_instance Sign.cert_arity (K I) (K I) - (fn _ => fn after_qed => Class.instantiation_instance (after_qed #> Class.conclude_instantiation)); + (fn _ => Class.instantiation_instance Class.conclude_instantiation) (Class.instance_arity I); val instance_cmd = gen_instance Sign.read_arity Attrib.intern_src Syntax.parse_prop - (fn _ => fn after_qed => Class.instantiation_instance (after_qed #> Class.conclude_instantiation)); + (fn _ => Class.instantiation_instance Class.conclude_instantiation) (Class.instance_arity I); fun prove_instance tac arities defs = gen_instance Sign.cert_arity (K I) (K I) - (fn defs => fn after_qed => Class.prove_instantiation_instance (K tac) - #> after_qed #> Class.conclude_instantiation #> ProofContext.theory_of #> pair defs) arities defs (K I); + (fn defs => Class.prove_instantiation_instance (K tac) + #> Class.conclude_instantiation #> ProofContext.theory_of #> pair defs) + (pair [] o ProofContext.theory_of o Proof.global_terminal_proof + (Method.Basic (K (Method.SIMPLE_METHOD tac), Position.none), NONE) + oo Class.instance_arity I) arities defs; end; diff -r 845883bd3a6b -r 9200b36280c0 src/Pure/Isar/isar_syn.ML --- a/src/Pure/Isar/isar_syn.ML Thu Nov 29 07:55:46 2007 +0100 +++ b/src/Pure/Isar/isar_syn.ML Thu Nov 29 17:08:26 2007 +0100 @@ -453,10 +453,8 @@ val _ = OuterSyntax.command "instance" "prove type arity or subclass relation" K.thy_goal ((P.xname -- ((P.$$$ "\\" || P.$$$ "<") |-- P.!!! P.xname) >> Class.classrel_cmd || - P.$$$ "advanced" |-- P.and_list1 P.arity -- Scan.repeat (SpecParse.opt_thm_name ":" -- P.prop) - >> (fn (arities, defs) => Instance.instance_cmd arities defs (K I)) || P.and_list1 P.arity -- Scan.repeat (SpecParse.opt_thm_name ":" -- P.prop) - >> (fn (arities, defs) => Class.instance_cmd arities defs (fold Code.add_default_func))) + >> (fn (arities, defs) => Instance.instance_cmd arities defs)) >> (Toplevel.print oo Toplevel.theory_to_proof) || Scan.succeed (Toplevel.print o Toplevel.local_theory_to_proof NONE (Class.instantiation_instance I)));