Arc Forumnew | comments | leaders | submitlogin
2 points by dfranke 5933 days ago | link | parent

This looks like perl's $_, but I don't see what it has to do with monads. What corresponds to >>= and return?


1 point by vrk 5932 days ago | link

Definitely $_, although the initial value has to be defined here explicitly.

-----

2 points by applepie 5932 days ago | link

Now it behaves as Haskell's do-notation for the identity monad.

It could be adapted for other monads if it also took return and (>>=) as arguments.

  (mac w/ (monad x . rest)
    (w/uniq (gmonad)
      ((afn (x rest)
         (if (no rest)
           `(let ,gmonad ,monad ,x)
           (self `((car ,gmonad) (fn (_) ,(car rest)) ,x)
                 (cdr rest))))
       `((cdr ,gmonad) ,x))))

  (= list-ret list)
  (= list-bind mappend)

  (= list-monad (cons list-bind list-ret))

  (w/ list-monad 10
     (list (- _ 1) _ (+ _ 1))
     (list _ (* _ 2) (* _ 3)))

  ===>
  (9 18 27 10 20 30 11 22 33)

-----