summaryrefslogtreecommitdiff
path: root/libstd/try.myr
diff options
context:
space:
mode:
authorOri Bernstein <ori@eigenstate.org>2014-05-08 14:51:33 -0400
committerOri Bernstein <ori@eigenstate.org>2014-05-08 14:51:33 -0400
commitf1858c72d837e2985995140fad77925515d6205f (patch)
treedfea159eda3765e81ddd55db985541c5aedad0fb /libstd/try.myr
parent61766f9822581c7f7ed44c66ff975517b350987a (diff)
downloadmc-f1858c72d837e2985995140fad77925515d6205f.tar.gz
Add 'try' to libstd.
This was something I had been thinking about doing, but never did until recently because of a compiler bug. Now it works.
Diffstat (limited to 'libstd/try.myr')
-rw-r--r--libstd/try.myr13
1 files changed, 13 insertions, 0 deletions
diff --git a/libstd/try.myr b/libstd/try.myr
new file mode 100644
index 0000000..1539a98
--- /dev/null
+++ b/libstd/try.myr
@@ -0,0 +1,13 @@
+use "option.use"
+use "fmt.use"
+
+pkg std =
+ generic try : (v : option(@a) -> @a)
+;;
+
+generic try = {v
+ match v
+ | `Some x: -> x
+ | `None: fatal(1, "expected `Some @a, got `None\n")
+ ;;
+}