doc-src/IsarAdvanced/Classes/Thy/Classes.thy
changeset 25868 97c6787099bc
parent 25533 0140cc7b26ad
child 25871 45753d56d935
equal deleted inserted replaced
25867:c24395ea4e71 25868:97c6787099bc
   569   \noindent yields the global definition of
   569   \noindent yields the global definition of
   570   @{term [source] "pow_int \<Colon> int \<Rightarrow> \<alpha>\<Colon>group \<Rightarrow> \<alpha>\<Colon>group"}
   570   @{term [source] "pow_int \<Colon> int \<Rightarrow> \<alpha>\<Colon>group \<Rightarrow> \<alpha>\<Colon>group"}
   571   with the corresponding theorem @{thm pow_int_def [no_vars]}.
   571   with the corresponding theorem @{thm pow_int_def [no_vars]}.
   572 *}
   572 *}
   573 
   573 
       
   574 subsection {* A note on syntax *}
       
   575 
       
   576 text {*
       
   577   As a commodity, class context syntax allows to refer
       
   578   to local class operations and their global conuterparts
       
   579   uniformly;  type inference resolves ambiguities.  For example:
       
   580 *}
       
   581 
       
   582 context semigroup
       
   583 begin
       
   584 
       
   585 term "x \<otimes> y" -- {* example 1 *}
       
   586 term "(x\<Colon>nat) \<otimes> y" -- {* example 2 *}
       
   587 
       
   588 end
       
   589 
       
   590 term "x \<otimes> y" -- {* example 3 *}
       
   591 
       
   592 text {*
       
   593   \noindent Here in example 1, the term refers to the local class operation
       
   594   @{text "mult [\<alpha>]"}, whereas in example 2 the type constraint
       
   595   enforces the global class operation @{text "mult [nat]"}.
       
   596   In the global context in example 3, the reference is
       
   597   to the polymorphic global class operation @{text "mult [?\<alpha> \<Colon> semigroup]"}.
       
   598 *}
   574 
   599 
   575 section {* Type classes and code generation *}
   600 section {* Type classes and code generation *}
   576 
   601 
   577 text {*
   602 text {*
   578   Turning back to the first motivation for type classes,
   603   Turning back to the first motivation for type classes,