On 17.03.2010, at 00:17, Steven E. Harris wrote:

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

There are a two kinds of inputs to a monadic computation in the state monad:
1) The initial state, provided when the computation is finally run.
2) The arguments to the functions that create the monadic values.

It seems that your confusion comes from the second case. Superficially, it 
looks rather different in Clojure and Haskell because Haskell programs use 
currying. Fundamentally, there is no difference, however.

Let's look at a simple use case:

(domonad state-m
   [x (fetch-val :x)]
  (set-val :x (+ x 2)))

This assumes that the state is a map, and adds 2 to the entry :x of the map. 
The two inputs to this computation are the map (provided when the computation 
is run), and the integer 2. This becomes even clearer when you define this as a 
named computational step:

(def add-to-x [y]
  (domonad state-m
    [x (fetch-val :x)]
    (set-val :x (+ x y))))

Now you can use this in a compound computation;

(domonad state-m
  [_ (add-to-x 2)
   _ (add-to-x 5)]
  nil)

Here it is pretty clear that 2 and 5 are inputs to the monadic computation. The 
key point is that each line of the domonad provides not a monadic value, but a 
function call that returns a monadic value. The arguments of that function call 
are all inputs to the computation.

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