diff options
Diffstat (limited to 'stdlib/source/lux/control/monad.lux')
-rw-r--r-- | stdlib/source/lux/control/monad.lux | 14 |
1 files changed, 5 insertions, 9 deletions
diff --git a/stdlib/source/lux/control/monad.lux b/stdlib/source/lux/control/monad.lux index 6e0992444..67f1fb047 100644 --- a/stdlib/source/lux/control/monad.lux +++ b/stdlib/source/lux/control/monad.lux @@ -3,7 +3,6 @@ [// ["." functor (#+ Functor)]]) -## [Utils] (def: (list/fold f init xs) (All [a b] (-> (-> b a a) a (List b) a)) @@ -41,10 +40,9 @@ _ #.Nil)) -## [Signatures] (signature: #export (Monad m) (: (Functor m) - functor) + &functor) (: (All [a] (-> a (m a))) wrap) @@ -52,12 +50,11 @@ (-> (m (m a)) (m a))) join)) -## [Syntax] (def: _cursor Cursor ["" 0 0]) (macro: #export (do tokens state) {#.doc (doc "Macro for easy concatenation of monadic operations." - (do Monad<Maybe> + (do monad [y (f1 x) z (f2 z)] (wrap (f3 z))))} @@ -80,7 +77,7 @@ body (reverse (as-pairs bindings)))] (#.Right [state (#.Cons (` ({(~' @) - ({{#..functor {#functor.map (~ g!map)} + ({{#..&functor {#functor.map (~ g!map)} #..wrap (~' wrap) #..join (~ g!join)} (~ body')} @@ -92,7 +89,6 @@ _ (#.Left "Wrong syntax for 'do'"))) -## [Functions] (def: #export (seq monad) {#.doc "Run all the monadic values in the list and produce a list of the base values."} (All [M a] @@ -162,11 +158,11 @@ [init' (f x init)] (fold monad f init' xs')))) -(def: #export (lift Monad<M> f) +(def: #export (lift monad f) {#.doc "Lift a normal function into the space of monads."} (All [M a b] (-> (Monad M) (-> a b) (-> (M a) (M b)))) (function (_ ma) - (do Monad<M> + (do monad [a ma] (wrap (f a))))) |