aboutsummaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorJan Tuomi <jans.tuomi@gmail.com>2022-12-09 18:16:41 +0200
committerJan Tuomi <jans.tuomi@gmail.com>2022-12-09 18:16:41 +0200
commitcff5a0dfa89ab3a7f95512382cedf88f8e1709d1 (patch)
treed6b49f3a49d623fdac1042b6de280886f587e5a1 /core
parent0ec99f0ddba6084df7c78ff905849a9d3d0a3c5b (diff)
Fix purity issue
Diffstat (limited to 'core')
-rw-r--r--core/common.milch7
-rw-r--r--core/result.milch7
2 files changed, 12 insertions, 2 deletions
diff --git a/core/common.milch b/core/common.milch
index cddf02f..2dc6698 100644
--- a/core/common.milch
+++ b/core/common.milch
@@ -1,8 +1,11 @@
;; Control flow
;;;;;;;;;;;;;;;;;;;;;;;;;
-(let . (\[f g]
- (\[x] (f (g x)))))
+; function composition
+(let . (\[f g x] (f (g x))))
+
+; impure version of .
+(let .! (\![f g x] (f (g x))))
(let flow (\[fs]
(foldr . id (reverse fs))))
diff --git a/core/result.milch b/core/result.milch
index f122ee6..903ca38 100644
--- a/core/result.milch
+++ b/core/result.milch
@@ -1,3 +1,5 @@
+(import "core/common")
+
(record Result/Ok value)
(record Result/Ex value)
@@ -23,3 +25,8 @@
(match (kind m)
:Result/Ok (Result/Ok/get-value m)
:Result/Ex (catch-f (Result/Ex/get-value m)))))
+
+; converts the given impure function that can throw a fatal error
+; to an impure function that returns a Result
+(let Result/safe! (\![fn! arg]
+ (try! Result/ex (.! Result/ok fn!) arg)))