summaryrefslogtreecommitdiff
path: root/libstd
diff options
context:
space:
mode:
authorOri Bernstein <ori@eigenstate.org>2015-06-14 18:54:07 -0700
committerOri Bernstein <ori@eigenstate.org>2015-06-15 01:19:24 -0700
commit527bad788adf057d71faa98ed6e09952395abe50 (patch)
tree61020c2252a42712f0f8d2063b67889a35d2bc46 /libstd
parent11dc97526dc9a7dcc30cb087b27f588c45266f03 (diff)
downloadmc-527bad788adf057d71faa98ed6e09952395abe50.tar.gz
Make try work ok std.result.
I kind of want that generically a bit more.
Diffstat (limited to 'libstd')
-rw-r--r--libstd/test/try.myr4
-rw-r--r--libstd/try.myr13
2 files changed, 14 insertions, 3 deletions
diff --git a/libstd/test/try.myr b/libstd/test/try.myr
index e8eea97..ef2c63f 100644
--- a/libstd/test/try.myr
+++ b/libstd/test/try.myr
@@ -2,5 +2,7 @@ use std
const main = {
var x = `std.Some 123
- std.assert(std.try(x) == 123, "expected 123 from try")
+ var r : std.result(int, byte[:]) = `std.Ok 666
+ std.assert(std.val(x) == 123, "expected 123 from try")
+ std.assert(std.try(r) == 666, "expected 123 from try")
}
diff --git a/libstd/try.myr b/libstd/try.myr
index 2997143..ea20f4e 100644
--- a/libstd/try.myr
+++ b/libstd/try.myr
@@ -1,13 +1,22 @@
+use "result.use"
use "option.use"
use "fmt.use"
pkg std =
- generic try : (v : option(@a) -> @a)
+ generic try : (v : result(@a, @b) -> @a)
+ generic val : (v : option(@a) -> @a)
;;
generic try = {v
match v
+ | `Ok x: -> x
+ | `Fail m: fatal("error: {}\n", m)
+ ;;
+}
+
+generic val = {v
+ match v
| `Some x: -> x
- | `None: fatal("expected `Some @a, got `None\n")
+ | `None: fatal("error: option had `None\n")
;;
}