Hi all, I'm trying to implement some simple macros to use monads in racket using a Haskell-like do notation. I have the following macros, and my problem is that I want the do macro to capture the bind identifier created by with-monad, and in each recursive step of the do macro expansion keep the same identifier. I don't know it is possible, I tried using (with-syntax ((bind (datum->syntax 'bind) ))) but it doesn't work.<br>
<br>Thanks<br><br>(module monad racket <br> (provide with-monad do)<br> <br> (define-syntax-rule (with-monad (<unit-f> <bind-f>) <body>)<br> (let ((unit <unit-f>)<br> (bind <bind-f>))<br>
<body>))<br><br> (define-syntax (do stx)<br> (syntax-case stx (let let* letrec letrec* <-)<br> ((do s) #'s)<br> ((do (x <- s) ss ...) #'(bind (lambda (x) (do ss ...)) s))<br> ((do (let bs) ss ...) #'(let bs (do ss ...)))<br>
((do (let* bs) ss ...) #'(let* bs (do ss ...)))<br> ((do (letrec bs) ss ...) #'(letrec bs (do ss ...)))<br> ((do (letrec* bs) ss ...) #'(letrec* bs (do ss ...)))<br> ((do s ss ...) #'(bind s (lambda (_) (do ss ...))))))<br>
)<br clear="all"><br>-- <br>Ismael<br><br>