equal
deleted
inserted
replaced
14 defaultsort cpo |
14 defaultsort cpo |
15 |
15 |
16 pcpodef (open) 'a maybe = "UNIV::(one ++ 'a u) set" |
16 pcpodef (open) 'a maybe = "UNIV::(one ++ 'a u) set" |
17 by simp_all |
17 by simp_all |
18 |
18 |
19 constdefs |
19 definition |
20 fail :: "'a maybe" |
20 fail :: "'a maybe" where |
21 "fail \<equiv> Abs_maybe (sinl\<cdot>ONE)" |
21 "fail = Abs_maybe (sinl\<cdot>ONE)" |
22 |
22 |
23 constdefs |
23 definition |
24 return :: "'a \<rightarrow> 'a maybe" where |
24 return :: "'a \<rightarrow> 'a maybe" where |
25 "return \<equiv> \<Lambda> x. Abs_maybe (sinr\<cdot>(up\<cdot>x))" |
25 "return = (\<Lambda> x. Abs_maybe (sinr\<cdot>(up\<cdot>x)))" |
26 |
26 |
27 definition |
27 definition |
28 maybe_when :: "'b \<rightarrow> ('a \<rightarrow> 'b) \<rightarrow> 'a maybe \<rightarrow> 'b::pcpo" where |
28 maybe_when :: "'b \<rightarrow> ('a \<rightarrow> 'b) \<rightarrow> 'a maybe \<rightarrow> 'b::pcpo" where |
29 "maybe_when = (\<Lambda> f r m. sscase\<cdot>(\<Lambda> x. f)\<cdot>(fup\<cdot>r)\<cdot>(Rep_maybe m))" |
29 "maybe_when = (\<Lambda> f r m. sscase\<cdot>(\<Lambda> x. f)\<cdot>(fup\<cdot>r)\<cdot>(Rep_maybe m))" |
30 |
30 |
56 "maybe_when\<cdot>f\<cdot>r\<cdot>(return\<cdot>x) = r\<cdot>x" |
56 "maybe_when\<cdot>f\<cdot>r\<cdot>(return\<cdot>x) = r\<cdot>x" |
57 by (simp_all add: return_def fail_def maybe_when_def cont_Rep_maybe |
57 by (simp_all add: return_def fail_def maybe_when_def cont_Rep_maybe |
58 cont_Abs_maybe Abs_maybe_inverse Rep_maybe_strict) |
58 cont_Abs_maybe Abs_maybe_inverse Rep_maybe_strict) |
59 |
59 |
60 translations |
60 translations |
61 "case m of fail \<Rightarrow> t1 | return\<cdot>x \<Rightarrow> t2" == "CONST maybe_when\<cdot>t1\<cdot>(\<Lambda> x. t2)\<cdot>m" |
61 "case m of XCONST fail \<Rightarrow> t1 | XCONST return\<cdot>x \<Rightarrow> t2" |
|
62 == "CONST maybe_when\<cdot>t1\<cdot>(\<Lambda> x. t2)\<cdot>m" |
62 |
63 |
63 |
64 |
64 subsubsection {* Monadic bind operator *} |
65 subsubsection {* Monadic bind operator *} |
65 |
66 |
66 definition |
67 definition |
161 |
162 |
162 lemmas run_fatbar_simps [simp] = run_fatbar1 run_fatbar2 run_fatbar3 |
163 lemmas run_fatbar_simps [simp] = run_fatbar1 run_fatbar2 run_fatbar3 |
163 |
164 |
164 subsection {* Case branch combinator *} |
165 subsection {* Case branch combinator *} |
165 |
166 |
166 constdefs |
167 definition |
167 branch :: "('a \<rightarrow> 'b maybe) \<Rightarrow> ('b \<rightarrow> 'c) \<rightarrow> ('a \<rightarrow> 'c maybe)" |
168 branch :: "('a \<rightarrow> 'b maybe) \<Rightarrow> ('b \<rightarrow> 'c) \<rightarrow> ('a \<rightarrow> 'c maybe)" where |
168 "branch p \<equiv> \<Lambda> r x. bind\<cdot>(p\<cdot>x)\<cdot>(\<Lambda> y. return\<cdot>(r\<cdot>y))" |
169 "branch p \<equiv> \<Lambda> r x. bind\<cdot>(p\<cdot>x)\<cdot>(\<Lambda> y. return\<cdot>(r\<cdot>y))" |
169 |
170 |
170 lemma branch_rews: |
171 lemma branch_rews: |
171 "p\<cdot>x = \<bottom> \<Longrightarrow> branch p\<cdot>r\<cdot>x = \<bottom>" |
172 "p\<cdot>x = \<bottom> \<Longrightarrow> branch p\<cdot>r\<cdot>x = \<bottom>" |
172 "p\<cdot>x = fail \<Longrightarrow> branch p\<cdot>r\<cdot>x = fail" |
173 "p\<cdot>x = fail \<Longrightarrow> branch p\<cdot>r\<cdot>x = fail" |