A major part of the "point" behind monads is that they can hide some
implicit parameter passing. In the case of State, the implicit
parameter is the current state and it is passed "inside" the bind
operator. Haskell is no different from Clojure on this point: 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.

N.B. the stateful computation itself -- the monadic value -- is
actually a function, both in Clojure and in Haskell (and presumably in
any other setting where people talk of the "state monad"). You can use
it multiple times, each time injecting a different initial value of
state. For this to be the case, you need to have a useful
representation of monadic values in State which you can carry around,
bind to names etc.; and in a Lambda the Ultimate kind of language like
Haskell and Clojure, a function is the natural fit.

For comparison, see how Haskell's State is an instance of MonadState
(in other words, here are the Haskell definitions of get and put; note
how put is a function returning a function when given a single
parameter):

http://hackage.haskell.org/packages/archive/mtl/1.1.0.2/doc/html/Control-Monad-State-Class.html#t%3AMonadState

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. Note that
the Haskell code prefers a point-free approach which actually looks
more like the c.c.m code. (Or you could say it emphasises the
function-returning nature of put, like c.c.m does.)

Sincerely,
Michał

PS. Sorry if this is a bit chaotic... I can't clean it up now, so I'll
post in the hope that it's a least somewhat helpful. Might take
another shot at it if it isn't.

-- 
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

Reply via email to