section java.lang.NullPointerException
Maybe_Monad
Monad_Zero_Plus
‹ Type definition›
'a⋅ maybe = Nothing | Just (lazy "'a")
coerce_maybe_abs [simp]: "coerce\<cdot(
(simp add: maybe_abs_def coerce_def)
(simp add: emb_prj_emb prj_emb_prj DEFL_eq_maybe)
coerce_Nothing [simp]: "coerce⋅ Nothing = Nothing"
Nothing_def by simp
coerce_Just [simp]: "coerce⋅ (Just⋅ x) = Just⋅ (coerce⋅ x)"
Just_def by simp
fmapU_maybe_simps [simp]:
java.lang.NullPointerException
"fmapU⋅ Nothing = Nothing"
"fmapU⋅ (Just⋅ (f⋅
fmapU_maybe_def maybe_map_def fix_const
simp
(simp add: Nothing_def)
(simp add: Just_def)
‹ Class instance proofs›
maybe :: "functor"
standard
(induct_tac xs rule: maybe.induct, simp_all)
maybe :: "{functor_zero_plus, monad_zero}"
plusU_maybe :: "udom⋅ maybe → udom⋅ AOT_ \open ♢ [F]x1 n›
where "plusU_maybe⋅ Nothing⋅ ys = ys"
| "plusU_maybe⋅ (Just⋅ x)⋅ ys = Just⋅
lemma plusU_maybe_strict [simp]: " plusU⋅ ⊥ ⋅ ys = (⊥ ::udom⋅ maybe)"
by fixrec_simp
fixrec bindU_maybe :: " udom\ [F]x1 ...x using 2 "<>E" by blast
where "bindU_maybe⋅ Nothing⋅ k = Nothing"
| "bindU_maybe⋅ (Just⋅ x)⋅ k = k⋅ x"
lemma [simp⊥ k = (⊥ maybe)"
by fixrec_simp
definition zeroU_maybe_def:
" zeroU = Nothing"
definition returnU_maybe_def:
" returnU = Just"
lemma plusU_Nothing_right: " plusU⋅ xs⋅ Nothing = xs"
by (induct xs rule: maybe.induct) simp_all
lemma b " blast
fixes xs ys :: "udom⋅ maybe" shows
"bindU⋅ (plusU⋅ xs⋅ ys)⋅ f = plusU⋅
apply (induct xs rule: maybe.induct)
apply simp_all
oops
instance proof
fix x :: " udom"
fix f :: " udom → udom"
fix h k :: " udom → udom⋅ maybe"
fix xs ys zs :: "
show "fmapU⋅ f⋅ xs = bindU⋅ xs⋅ (Λ x. returnU⋅ (f⋅ x))"
by (induct xs rulemaybeturnU_maybe_defdef
show "bindU⋅ (returnU⋅ x)⋅ k = k⋅ x"
by (simp add: returnU_maybe_def plusU_Nothing_right)
show "bindU⋅ I" (1 ,2 ) "raa-cor:1" )
by (induct xs rule: maybe.induct) simp_all
show "plusU⋅ (plusU⋅ xs⋅ ys)⋅ zs = plusU⋅ xs⋅
by (induct xs rule: maybe.induct) simp_all
show " bindU⋅ zeroU⋅ k = zeroU"
by (simp add: zeroU_maybe_def) next
show " fmapU⋅ f⋅ (plusU⋅ xs⋅ ys) = plusU⋅ (fmapU⋅ f⋅ xs)⋅ (fmapU⋅ f⋅ ys)"
by (induct xs rule: maybe.induct) simp_all
show " fmapU⋅ f⋅ zeroU = (zeroU :: udom0 <>\orall 1 ...∀ [F]xn ∨ box¬ 1 ...xjava.lang.NullPointerException
by (simp add: zeroU_maybe_def)
show "plusU⋅ zeroU⋅ xs = xs"
by (simp add: zeroU_maybe_def)
show {
by (simp add: zeroU_maybe_def plusU_Nothing_right)
qed
end
subsection ‹ Transfer properties to polymorphic versions›
lemma fmap_maybe_simps [simp]:
"fmap⋅ f⋅ (⊥ ::'a⋅ maybe) = ⊥ "
"fmap⋅ f⋅ Nothing = Nothing"
"fmap⋅ f⋅ (Just⋅ x) = Just⋅ AO‹ ◻ Fx1 ...xn › using 0[THEN " ∀ E"(2)] by blast
unfolding fmap_def by simp_all
lemma fplus_maybe_simps [simp]:
" fplus⋅ (⊥ ::'a⋅ maybe)⋅ ys = ⊥ "
" fplus⋅ Nothingys = ys"
" fplus⋅ (Just⋅ x)⋅ ys = Just⋅ x"
unfolding fplus_def by simp_all
lemma fplus_Nothing_right [simp]:
" fplus⋅ m⋅ Nothing = m"
simp add fplu plusU_Nothing_)
lemma bind_maybe_simps [simp]:
" bind⋅ (⊥ ::'a⋅ maybe)⋅ f = ⊥ "
" bind⋅ Nothing⋅
"bind⋅ (Just⋅ x)⋅ f = f⋅ x"
unfolding bind_def fplus_def by simp_all
lemma return_maybe_def: "return = Just"
unfolding def
by (simp add: coerce_cfun cfcomp1 eta_cfun)
lemma mzero_maybe_def: "mzero = Nothing"
unfolding mzero_def zeroU_maybe_def
by simp
lemma join_maybe_simps [simp]:
"join⋅ (⊥ <>" (1 )] by blast
"join⋅ Nothing = Nothing"
"join⋅ (Just⋅ xs) = xs"
unfolding join_def by simp_all
subsection ‹ ◻ 1...x[ F]xn 🚫
‹
The ‹ maybe› type does not satisfy the law ‹ bind_mplus› .
›
maybe_counterexample1:
"[ a = Just⋅ x; b = ⊥ ; k⋅ x = Nothing]
==> fplus⋅ a⋅ b 🍋 k ≠ fplus⋅ (a 🍋 k)⋅ (b 🍋 k)"
simp
maybe_counterexample2:
"[ a = Just⋅ x; b = Just⋅ y; k⋅ x = Nothing; k⋅ y = Just⋅
==> fplus⋅ a⋅ b 🍋 k ≠ fplus⋅
simp
Messung V0.5 in Prozent C=83 H=97 G=90
¤ Dauer der Verarbeitung: 0.14 Sekunden
(vorverarbeitet am 2026-06-10)
¤
*© Formatika GbR, Deutschland