lib: add some basic option monad functions
Signed-off-by: Miki Tanaka <miki.tanaka@data61.csiro.au>
This commit is contained in:
parent
65b7139398
commit
f6d919f159
|
@ -100,6 +100,12 @@ definition oapply :: "'a \<Rightarrow> ('a \<Rightarrow> 'b option) \<Rightarrow
|
||||||
definition oliftM :: "('a \<Rightarrow> 'b) \<Rightarrow> ('s,'a) lookup \<Rightarrow> ('s,'b) lookup" where
|
definition oliftM :: "('a \<Rightarrow> 'b) \<Rightarrow> ('s,'a) lookup \<Rightarrow> ('s,'b) lookup" where
|
||||||
"oliftM f m \<equiv> do { x \<leftarrow> m; oreturn (f x) }"
|
"oliftM f m \<equiv> do { x \<leftarrow> m; oreturn (f x) }"
|
||||||
|
|
||||||
|
definition ounless :: "bool \<Rightarrow> ('s, unit) lookup \<Rightarrow> ('s, unit) lookup" where
|
||||||
|
"ounless P f \<equiv> if P then oreturn () else f"
|
||||||
|
|
||||||
|
definition owhen :: "bool \<Rightarrow> ('s, unit) lookup \<Rightarrow> ('s, unit) lookup" where
|
||||||
|
"owhen P f \<equiv> if P then f else oreturn ()"
|
||||||
|
|
||||||
(* Reader monad interface: *)
|
(* Reader monad interface: *)
|
||||||
abbreviation (input)
|
abbreviation (input)
|
||||||
"ask \<equiv> Some"
|
"ask \<equiv> Some"
|
||||||
|
|
Loading…
Reference in New Issue