summaryrefslogtreecommitdiff
path: root/backends/lean/Base
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--backends/lean/Base/Primitives/Base.lean5
-rw-r--r--backends/lean/Base/Primitives/Core.lean8
-rw-r--r--backends/lean/Base/Primitives/Scalar.lean5
3 files changed, 13 insertions, 5 deletions
diff --git a/backends/lean/Base/Primitives/Base.lean b/backends/lean/Base/Primitives/Base.lean
index 4c5b2795..ac4fd340 100644
--- a/backends/lean/Base/Primitives/Base.lean
+++ b/backends/lean/Base/Primitives/Base.lean
@@ -76,6 +76,11 @@ def eval_global {α: Type u} (x: Result α) (_: ok? x := by prove_eval_global) :
| fail _ | div => by contradiction
| ok x => x
+def Result.ofOption {a : Type u} (x : Option a) (e : Error) : Result a :=
+ match x with
+ | some x => ok x
+ | none => fail e
+
/- DO-DSL SUPPORT -/
def bind {α : Type u} {β : Type v} (x: Result α) (f: α → Result β) : Result β :=
diff --git a/backends/lean/Base/Primitives/Core.lean b/backends/lean/Base/Primitives/Core.lean
index 99f65985..b7dd6d2c 100644
--- a/backends/lean/Base/Primitives/Core.lean
+++ b/backends/lean/Base/Primitives/Core.lean
@@ -51,4 +51,12 @@ def clone.CloneBool : clone.Clone Bool := {
clone := fun b => ok (clone.impls.CloneBool.clone b)
}
+namespace option
+
+/- [core::option::{core::option::Option<T>}::unwrap] -/
+def Option.unwrap (T : Type) (x : Option T) : Result T :=
+ Result.ofOption x Error.panic
+
+end option -- core.option
+
end core
diff --git a/backends/lean/Base/Primitives/Scalar.lean b/backends/lean/Base/Primitives/Scalar.lean
index 014decb1..2bee8a2f 100644
--- a/backends/lean/Base/Primitives/Scalar.lean
+++ b/backends/lean/Base/Primitives/Scalar.lean
@@ -364,11 +364,6 @@ def Scalar.tryMkOpt (ty : ScalarTy) (x : Int) : Option (Scalar ty) :=
some (Scalar.ofIntCore x (Scalar.check_bounds_imp_in_bounds h))
else none
-def Result.ofOption {a : Type u} (x : Option a) (e : Error) : Result a :=
- match x with
- | some x => ok x
- | none => fail e
-
def Scalar.tryMk (ty : ScalarTy) (x : Int) : Result (Scalar ty) :=
Result.ofOption (tryMkOpt ty x) integerOverflow