mirror of
https://github.com/correl/calrissian.git
synced 2024-11-23 11:09:58 +00:00
Generalize calls to monad functions
Use call instead of : to call functions on monad modules in order to support tuple modules. This will come in handy when implementing monad transformers.
This commit is contained in:
parent
df4d65f0b3
commit
f88d977017
2 changed files with 14 additions and 5 deletions
|
@ -4,16 +4,25 @@
|
||||||
(monad:do-transform monad statements)))
|
(monad:do-transform monad statements)))
|
||||||
|
|
||||||
(defmacro >>= (monad m f)
|
(defmacro >>= (monad m f)
|
||||||
`(: ,monad >>= ,m ,f))
|
(if (: lfe-utils atom? monad)
|
||||||
|
`(call ',monad '>>= ,m ,f)
|
||||||
|
`(call ,monad '>>= ,m ,f)))
|
||||||
|
|
||||||
(defmacro >> (monad m1 m2)
|
(defmacro >> (monad m1 m2)
|
||||||
`(: ,monad >>= ,m1 (lambda (_) ,m2)))
|
(let ((f `(lambda (_) ,m2)))
|
||||||
|
(if (: lfe-utils atom? monad)
|
||||||
|
`(call ',monad '>>= ,m1 ,f)
|
||||||
|
`(call ,monad '>>= ,m1 ,f))))
|
||||||
|
|
||||||
(defmacro return (monad expr)
|
(defmacro return (monad expr)
|
||||||
`(: ,monad return ,expr))
|
(if (: lfe-utils atom? monad)
|
||||||
|
`(call ',monad 'return ,expr)
|
||||||
|
`(call ,monad 'return ,expr)))
|
||||||
|
|
||||||
(defmacro fail (monad expr)
|
(defmacro fail (monad expr)
|
||||||
`(: ,monad fail ,expr))
|
(if (: lfe-utils atom? monad)
|
||||||
|
`(call ',monad 'fail ,expr)
|
||||||
|
`(call ,monad 'fail ,expr)))
|
||||||
|
|
||||||
(defmacro sequence (monad list)
|
(defmacro sequence (monad list)
|
||||||
`(: lists foldr
|
`(: lists foldr
|
||||||
|
|
|
@ -10,7 +10,7 @@
|
||||||
|
|
||||||
(defun do-transform
|
(defun do-transform
|
||||||
((monad (cons h '())) h)
|
((monad (cons h '())) h)
|
||||||
((monad (cons (list f '<- m) t)) (list ': monad '>>=
|
((monad (cons (list f '<- m) t)) (list '>>= monad
|
||||||
m
|
m
|
||||||
(list 'lambda (list f) (do-transform monad t))))
|
(list 'lambda (list f) (do-transform monad t))))
|
||||||
((monad (cons h t)) (list '>> monad h (do-transform monad t)))
|
((monad (cons h t)) (list '>> monad h (do-transform monad t)))
|
||||||
|
|
Loading…
Reference in a new issue