Michał Marczyk <michal.marc...@gmail.com> writes: > a State-using programme builds up a stateful computation first, then > uses runState (or perhaps execState / evalState) to run it as a whole; > only at this final step does the initial state actually get poured > into the opening of the monadic pipe, as it were.
That's a good metaphor. [...] > You can use it multiple times, each time injecting a different initial > value of state. Ah, but here's where part of my confusion arises. With this treatment of such a built-up computation, it's a kind of a zero-argument function, in that there's no way to pass in a "basic value" to kick it off. Where does the first "basic value" to be fed into the first monadic function come from? Presumably it comes from the first monadic value in the "pipe". In your description above, it sounds like this first monadic value must be committed to when "buld[ing] up a stateful computation first". In the parser examples I've seen, the state provides the input value. It's hard to find examples of other kinds of computations using the state monad, but even something like "do these arithmetic steps to some input number, and count the number of operations in the state" would want to start off with some number as input, distinct from the state, which would presumably start off with a count of zero. That sounds like we'd have to build up the arithmetic steps as a monadic function, not a monadic value, which we'd bind to (m-result initial-value) to kick it off. [...] > BTW, if you feel you'd rather write something like (defn put [v s] [v > v]) than a "two-tier" function like c.c.monads/set-state, you're free > to do so; then you can use #(partial put %) for set-state. Interesting idea. > PS. Sorry if this is a bit chaotic... I like the challenge of following your mental process. More examples on this topic would be welcome. -- Steven E. Harris -- 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