> What would be lost by defining Clojure bind operator like this: > > (fn m-bind-state [mv f] > (fn [s] > (let [[v ss] (mv s)] > (f v ss)))) > > Is there more to it than, "Monadic functions must return monadic > values.
My first thought was that it would be problematic for the "result" operator, which would have to take two parameters (or at least accept two parameters, with a default if passed only one) Perhaps more importantly, the power of the monad abstraction is that the types of monadic functions and all the operators are similar. ie. *all* monadic functions, regardless of the monad, have the (haskell) type a -> M b This way, you can write a function that works under many different monads, as long as it uses the generic facilities to return monadic values. eg. a lifted inc: (defn m-inc [v] (m-result (inc v)) which can be used in the state monad as an argument to bind, even though it doesn't care about the state at all. If you *do* need the state (add it to the parameter, for example), you would write (defn add-state [v] (fn [s] [(+ v s) s])) used like ((m-bind (m-result 4) add-state) 10), giving [14 10] I hope I got this correct... I'm not an expert on all the mathematical theory behind monads. -- 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 Note that posts from new members are moderated - please be patient with your first post. 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