monads: Inline the procedure returned by liftN.

* guix/monads.scm (define-lift): Turn into a macro that open-codes the result
  of its lift.
This commit is contained in:
Ludovic Courtès 2015-08-28 15:17:20 +02:00
parent ca2a55d46b
commit b6c6105cac
1 changed files with 18 additions and 5 deletions

View File

@ -225,11 +225,24 @@ CONDITION is true, return *unspecified* in the current monad."
(define-syntax define-lift (define-syntax define-lift
(syntax-rules () (syntax-rules ()
((_ liftn (args ...)) ((_ liftn (args ...))
(define (liftn proc monad) (define-syntax liftn
"Lift PROC to MONAD---i.e., return a monadic function in MONAD." (lambda (s)
(lambda (args ...) "Lift PROC to MONAD---i.e., return a monadic function in MONAD."
(with-monad monad (syntax-case s ()
(return (proc args ...)))))))) ((liftn proc monad)
;; Inline the result of lifting PROC, such that 'return' can in
;; turn be open-coded.
#'(lambda (args ...)
(with-monad monad
(return (proc args ...)))))
(id
(identifier? #'id)
;; Slow path: Return a closure-returning procedure (we don't
;; guarantee (eq? LIFTN LIFTN), but that's fine.)
(lambda (liftn proc monad)
(lambda (args ...)
(with-monad monad
(return (proc args ...))))))))))))
(define-lift lift0 ()) (define-lift lift0 ())
(define-lift lift1 (a)) (define-lift lift1 (a))