diff --git a/lib/Monads/nondet/Nondet_Monad.thy b/lib/Monads/nondet/Nondet_Monad.thy index 2b86dce5df..e14cf17fd2 100644 --- a/lib/Monads/nondet/Nondet_Monad.thy +++ b/lib/Monads/nondet/Nondet_Monad.thy @@ -71,15 +71,15 @@ text \ operation may have failed, if @{text f} may have failed or @{text g} may have failed on any of the results of @{text f}.\ definition bind :: - "('s, 'a) nondet_monad \ ('a \ ('s, 'b) nondet_monad) \ ('s, 'b) nondet_monad" - (infixl ">>=" 60) where + "('s, 'a) nondet_monad \ ('a \ ('s, 'b) nondet_monad) \ ('s, 'b) nondet_monad" (infixl ">>=" 60) + where "bind f g \ \s. (\(fst ` case_prod g ` fst (f s)), True \ snd ` case_prod g ` fst (f s) \ snd (f s))" text \Sometimes it is convenient to write @{text bind} in reverse order.\ abbreviation (input) bind_rev :: - "('c \ ('a, 'b) nondet_monad) \ ('a, 'c) nondet_monad \ ('a, 'b) nondet_monad" - (infixl "=<<" 60) where + "('c \ ('a, 'b) nondet_monad) \ ('a, 'c) nondet_monad \ ('a, 'b) nondet_monad" (infixl "=<<" 60) + where "g =<< f \ f >>= g" text \ @@ -106,8 +106,8 @@ definition select :: "'a set \ ('s,'a) nondet_monad" where "select A \ \s. (A \ {s}, False)" definition alternative :: - "('s, 'a) nondet_monad \ ('s, 'a) nondet_monad \ ('s, 'a) nondet_monad" - (infixl "\" 20) where + "('s, 'a) nondet_monad \ ('s, 'a) nondet_monad \ ('s, 'a) nondet_monad" (infixl "\" 20) + where "f \ g \ \s. (fst (f s) \ fst (g s), snd (f s) \ snd (g s))" text \ @@ -559,8 +559,8 @@ text \ if the left-hand side throws no exception:\ definition handle_elseE :: "('s, 'e + 'a) nondet_monad \ ('e \ ('s, 'ee + 'b) nondet_monad) \ - ('a \ ('s, 'ee + 'b) nondet_monad) \ ('s, 'ee + 'b) nondet_monad" - ("_ _ _" 10) where + ('a \ ('s, 'ee + 'b) nondet_monad) \ ('s, 'ee + 'b) nondet_monad" ("_ _ _" 10) + where "f handler continue \ do v \ f; case v of Inl e \ handler e diff --git a/lib/Monads/trace/Trace_Monad.thy b/lib/Monads/trace/Trace_Monad.thy index c2eaa42beb..f0d093b77e 100644 --- a/lib/Monads/trace/Trace_Monad.thy +++ b/lib/Monads/trace/Trace_Monad.thy @@ -135,8 +135,9 @@ text \ definition select :: "'a set \ ('s, 'a) tmonad" where "select A \ \s. (Pair [] ` Result ` (A \ {s}))" -definition alternative :: "('s,'a) tmonad \ ('s,'a) tmonad \ ('s,'a) tmonad" - (infixl "\" 20) where +definition alternative :: + "('s,'a) tmonad \ ('s,'a) tmonad \ ('s,'a) tmonad" (infixl "\" 20) + where "f \ g \ \s. (f s \ g s)" text \ @@ -315,8 +316,8 @@ text \ the right-hand side is skipped if the left-hand side produced an exception.\ definition bindE :: - "('s, 'e + 'a) tmonad \ ('a \ ('s, 'e + 'b) tmonad) \ ('s, 'e + 'b) tmonad" - (infixl ">>=E" 60) where + "('s, 'e + 'a) tmonad \ ('a \ ('s, 'e + 'b) tmonad) \ ('s, 'e + 'b) tmonad" (infixl ">>=E" 60) + where "f >>=E g \ f >>= lift g" text \ @@ -652,8 +653,8 @@ text \ practice: the exception handle (potentially) throws exception of the same type as the left-hand side.\ definition handleE :: - "('s, 'x + 'a) tmonad \ ('x \ ('s, 'x + 'a) tmonad) \ ('s, 'x + 'a) tmonad" - (infix "" 10) where + "('s, 'x + 'a) tmonad \ ('x \ ('s, 'x + 'a) tmonad) \ ('s, 'x + 'a) tmonad" (infix "" 10) + where "handleE \ handleE'" text \ @@ -661,8 +662,8 @@ text \ if the left-hand side throws no exception:\ definition handle_elseE :: "('s, 'e + 'a) tmonad \ ('e \ ('s, 'ee + 'b) tmonad) \ ('a \ ('s, 'ee + 'b) tmonad) \ - ('s, 'ee + 'b) tmonad" - ("_ _ _" 10) where + ('s, 'ee + 'b) tmonad" ("_ _ _" 10) + where "f handler continue \ do v \ f; case v of Inl e \ handler e