src/HOLCF/Fixrec.thy
changeset 16551 7abf8a713613
parent 16463 342d74ca8815
child 16754 1b979f8b7e8e
equal deleted inserted replaced
16550:e14b89d6ef13 16551:7abf8a713613
     4 *)
     4 *)
     5 
     5 
     6 header "Package for defining recursive functions in HOLCF"
     6 header "Package for defining recursive functions in HOLCF"
     7 
     7 
     8 theory Fixrec
     8 theory Fixrec
     9 imports Ssum One Up Fix Tr
     9 imports Sprod Ssum Up One Tr Fix
    10 uses ("fixrec_package.ML")
    10 uses ("fixrec_package.ML")
    11 begin
    11 begin
    12 
    12 
    13 subsection {* Maybe monad type *}
    13 subsection {* Maybe monad type *}
    14 
    14 
   117 lemma mplus_assoc: "(x +++ y) +++ z = x +++ (y +++ z)"
   117 lemma mplus_assoc: "(x +++ y) +++ z = x +++ (y +++ z)"
   118 by (rule_tac p=x in maybeE, simp_all)
   118 by (rule_tac p=x in maybeE, simp_all)
   119 
   119 
   120 subsection {* Match functions for built-in types *}
   120 subsection {* Match functions for built-in types *}
   121 
   121 
   122 text {* Currently the package only supports lazy constructors *}
       
   123 
       
   124 constdefs
   122 constdefs
   125   match_cpair :: "'a \<times> 'b \<rightarrow> ('a \<times> 'b) maybe"
   123   match_cpair :: "'a \<times> 'b \<rightarrow> ('a \<times> 'b) maybe"
   126   "match_cpair \<equiv> csplit\<cdot>(\<Lambda> x y. return\<cdot><x,y>)"
   124   "match_cpair \<equiv> csplit\<cdot>(\<Lambda> x y. return\<cdot><x,y>)"
       
   125 
       
   126   match_spair :: "'a \<otimes> 'b \<rightarrow> ('a \<times> 'b) maybe"
       
   127   "match_spair \<equiv> ssplit\<cdot>(\<Lambda> x y. return\<cdot><x,y>)"
       
   128 
       
   129   match_sinl :: "'a \<oplus> 'b \<rightarrow> 'a maybe"
       
   130   "match_sinl \<equiv> sscase\<cdot>return\<cdot>(\<Lambda> y. fail)"
       
   131 
       
   132   match_sinr :: "'a \<oplus> 'b \<rightarrow> 'b maybe"
       
   133   "match_sinr \<equiv> sscase\<cdot>(\<Lambda> x. fail)\<cdot>return"
   127 
   134 
   128   match_up :: "'a u \<rightarrow> 'a maybe"
   135   match_up :: "'a u \<rightarrow> 'a maybe"
   129   "match_up \<equiv> fup\<cdot>return"
   136   "match_up \<equiv> fup\<cdot>return"
   130 
   137 
   131   match_ONE :: "one \<rightarrow> unit maybe"
   138   match_ONE :: "one \<rightarrow> unit maybe"
   138   "match_FF \<equiv> flift1 (\<lambda>b. if b then fail else return\<cdot>())"
   145   "match_FF \<equiv> flift1 (\<lambda>b. if b then fail else return\<cdot>())"
   139 
   146 
   140 lemma match_cpair_simps [simp]:
   147 lemma match_cpair_simps [simp]:
   141   "match_cpair\<cdot><x,y> = return\<cdot><x,y>"
   148   "match_cpair\<cdot><x,y> = return\<cdot><x,y>"
   142 by (simp add: match_cpair_def)
   149 by (simp add: match_cpair_def)
       
   150 
       
   151 lemma match_spair_simps [simp]:
       
   152   "\<lbrakk>x \<noteq> \<bottom>; y \<noteq> \<bottom>\<rbrakk> \<Longrightarrow> match_spair\<cdot>(:x,y:) = return\<cdot><x,y>"
       
   153   "match_spair\<cdot>\<bottom> = \<bottom>"
       
   154 by (simp_all add: match_spair_def)
       
   155 
       
   156 lemma match_sinl_simps [simp]:
       
   157   "x \<noteq> \<bottom> \<Longrightarrow> match_sinl\<cdot>(sinl\<cdot>x) = return\<cdot>x"
       
   158   "x \<noteq> \<bottom> \<Longrightarrow> match_sinl\<cdot>(sinr\<cdot>x) = fail"
       
   159   "match_sinl\<cdot>\<bottom> = \<bottom>"
       
   160 by (simp_all add: match_sinl_def)
       
   161 
       
   162 lemma match_sinr_simps [simp]:
       
   163   "x \<noteq> \<bottom> \<Longrightarrow> match_sinr\<cdot>(sinr\<cdot>x) = return\<cdot>x"
       
   164   "x \<noteq> \<bottom> \<Longrightarrow> match_sinr\<cdot>(sinl\<cdot>x) = fail"
       
   165   "match_sinr\<cdot>\<bottom> = \<bottom>"
       
   166 by (simp_all add: match_sinr_def)
   143 
   167 
   144 lemma match_up_simps [simp]:
   168 lemma match_up_simps [simp]:
   145   "match_up\<cdot>(up\<cdot>x) = return\<cdot>x"
   169   "match_up\<cdot>(up\<cdot>x) = return\<cdot>x"
   146   "match_up\<cdot>\<bottom> = \<bottom>"
   170   "match_up\<cdot>\<bottom> = \<bottom>"
   147 by (simp_all add: match_up_def)
   171 by (simp_all add: match_up_def)