doc-src/IsarAdvanced/Classes/Thy/Classes.thy
changeset 29513 363f17dee9ca
parent 29294 6cd3ac4708d2
child 29705 a1ecdd8cf81c
equal deleted inserted replaced
29512:25472dc71a4b 29513:363f17dee9ca
   366 consts %quote f :: "\<alpha> \<Rightarrow> \<alpha>"
   366 consts %quote f :: "\<alpha> \<Rightarrow> \<alpha>"
   367 
   367 
   368 text {*
   368 text {*
   369   \noindent The connection to the type system is done by means
   369   \noindent The connection to the type system is done by means
   370   of a primitive axclass
   370   of a primitive axclass
   371 *}
   371 *} setup %invisible {* Sign.add_path "foo" *}
   372 
   372 
   373 axclass %quote idem < type
   373 axclass %quote idem < type
   374   idem: "f (f x) = f x"
   374   idem: "f (f x) = f x" setup %invisible {* Sign.parent_path *}
   375 
   375 
   376 text {* \noindent together with a corresponding interpretation: *}
   376 text {* \noindent together with a corresponding interpretation: *}
   377 
   377 
   378 interpretation %quote idem_class':    (* FIXME proper prefix? *)
   378 interpretation %quote idem_class:
   379   idem "f \<Colon> (\<alpha>\<Colon>idem) \<Rightarrow> \<alpha>"
   379   idem "f \<Colon> (\<alpha>\<Colon>idem) \<Rightarrow> \<alpha>"
   380 proof qed (rule idem)
   380 proof qed (rule idem)
   381 
   381 
   382 text {*
   382 text {*
   383   \noindent This gives you at hand the full power of the Isabelle module system;
   383   \noindent This gives you at hand the full power of the Isabelle module system;
   457   the same operations as for genuinely algebraic types.
   457   the same operations as for genuinely algebraic types.
   458   In such a case, we simply can do a particular interpretation
   458   In such a case, we simply can do a particular interpretation
   459   of monoids for lists:
   459   of monoids for lists:
   460 *}
   460 *}
   461 
   461 
   462 class_interpretation %quote list_monoid: monoid [append "[]"]
   462 interpretation %quote list_monoid!: monoid append "[]"
   463   proof qed auto
   463   proof qed auto
   464 
   464 
   465 text {*
   465 text {*
   466   \noindent This enables us to apply facts on monoids
   466   \noindent This enables us to apply facts on monoids
   467   to lists, e.g. @{thm list_monoid.neutl [no_vars]}.
   467   to lists, e.g. @{thm list_monoid.neutl [no_vars]}.
   472 
   472 
   473 primrec %quote replicate :: "nat \<Rightarrow> \<alpha> list \<Rightarrow> \<alpha> list" where
   473 primrec %quote replicate :: "nat \<Rightarrow> \<alpha> list \<Rightarrow> \<alpha> list" where
   474   "replicate 0 _ = []"
   474   "replicate 0 _ = []"
   475   | "replicate (Suc n) xs = xs @ replicate n xs"
   475   | "replicate (Suc n) xs = xs @ replicate n xs"
   476 
   476 
   477 class_interpretation %quote list_monoid: monoid [append "[]"] where
   477 interpretation %quote list_monoid!: monoid append "[]" where
   478   "monoid.pow_nat append [] = replicate"
   478   "monoid.pow_nat append [] = replicate"
   479 proof -
   479 proof -
   480   class_interpret monoid [append "[]"] ..
   480   interpret monoid append "[]" ..
   481   show "monoid.pow_nat append [] = replicate"
   481   show "monoid.pow_nat append [] = replicate"
   482   proof
   482   proof
   483     fix n
   483     fix n
   484     show "monoid.pow_nat append [] n = replicate n"
   484     show "monoid.pow_nat append [] n = replicate n"
   485       by (induct n) auto
   485       by (induct n) auto