aboutsummaryrefslogtreecommitdiffstats
path: root/src/Common/Helper.v
diff options
context:
space:
mode:
Diffstat (limited to 'src/Common/Helper.v')
-rw-r--r--src/Common/Helper.v21
1 files changed, 21 insertions, 0 deletions
diff --git a/src/Common/Helper.v b/src/Common/Helper.v
new file mode 100644
index 0000000..292d011
--- /dev/null
+++ b/src/Common/Helper.v
@@ -0,0 +1,21 @@
+Module Option.
+
+Definition default {T : Type} (x : T) (u : option T) : T :=
+ match u with
+ | Some y => y
+ | _ => x
+ end.
+
+Definition map {S : Type} {T : Type} (f : S -> T) (u : option S) : option T :=
+ match u with
+ | Some y => Some (f y)
+ | _ => None
+ end.
+
+Definition liftA2 {T : Type} (f : T -> T -> T) (a : option T) (b : option T) : option T :=
+ match a with
+ | Some x => map (f x) b
+ | _ => None
+ end.
+
+End Option.