state monad transformer

2009-02-16 Thread jim

Konrad,

Here's a shot at implementing a monad transformer for the state
monad.  Any chance of getting it added to clojure.contrib.monads?

(defn state-t [m]
   (monad [m-result (with-monad m
 (fn [v]
   (fn [s]
   (m-result (list v s)

   m-bind   (with-monad m
  (fn [stm f]
   (fn [s]
 (m-bind (stm s)
 (fn [[v ss]]
   ((f v) ss))

  m-zero   (with-monad m
  (when (not= ::undefined m-zero)
(fn [s]
m-zero)))

  m-plus   (with-monad m
  (when (not= ::undefined m-zero)
   (fn [& stms]
 (fn [s] (apply m-plus (map #(% s) stms))
  ]))

I've also about finished with the first draft of a monad tutorial for
Clojure based on clojure.contrib.monads.

Jim
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: state monad transformer

2009-02-17 Thread Konrad Hinsen

On 16.02.2009, at 23:38, jim wrote:

> Here's a shot at implementing a monad transformer for the state
> monad.  Any chance of getting it added to clojure.contrib.monads?

If you are on the list of contributors (those who have signed a  
contributor agreement), yes, of course!

Konrad.


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---