aboutsummaryrefslogtreecommitdiff
path: root/control/monad.scm
diff options
context:
space:
mode:
Diffstat (limited to 'control/monad.scm')
-rw-r--r--control/monad.scm16
1 files changed, 14 insertions, 2 deletions
diff --git a/control/monad.scm b/control/monad.scm
index e964b48..4b756c7 100644
--- a/control/monad.scm
+++ b/control/monad.scm
@@ -37,6 +37,17 @@
;;; ----------------------------------------
+;; This makes all curly infix operators be left associative,
+;; discarding regular order of operations.
+;; It does however work in my below example where I do
+;; > f <$> a <*> b
+;; Which is all that really matters.
+(define-syntax $nfx$
+ (syntax-rules ()
+ ((_ single) single)
+ ((_ a * b rest ...)
+ ($nfx$ (* a b) rest ...))))
+
;; sequence :: (list (M a)) → M (list a)
(define (sequence in-list)
"Evaluate each monadic action in the structure from left to right, and collect
@@ -44,7 +55,8 @@ the results. For a version that ignores the results see sequence_.
https://hackage.haskell.org/package/base-4.12.0.0/docs/Control-Monad.html#g:4"
(define ((f done) item) (append done (list item)))
(fold (lambda (m-item m-done)
- #!curly-infix {{ f <$> m-done } <*> m-item })
+ #!curly-infix { f <$> m-done <*> m-item })
+ ;; TODO this fails on a list of length 0
((return (car in-list)) '())
in-list))
@@ -54,4 +66,4 @@ https://hackage.haskell.org/package/base-4.12.0.0/docs/Control-Monad.html#g:4"
left to right, and collect the results. For a version that ignores the results
see mapM_.
https://hackage.haskell.org/package/base-4.12.0.0/docs/Control-Monad.html#g:4"
- (sequence (map proc items)))
+ (sequence (map (lambda (x) (>>= x proc)) items)))