On Mon, Dec 21, 2009 at 7:18 PM, jim <jim.d...@gmail.com> wrote:
> Just posted a short piece on why monads are useful. This was prompted
> by some conversations last week with some folks. Comments, questions
> and criticisms welcome.
>
> http://intensivesystems.net/tutorials/why_monads.html

Thanks for writing that up.  I keep reading approachable tidbits
about monads like this, without really digging into learning all
there is to know about monads.  It's hardly fair of me to comment
on this at all before I do that deeper digging, but for what it's
worth here's a non-monadic solution to the particular problem
presented.  It's just a high-level function that defines
a comp-like fn with the desired behavior:

  (defn maybe-comp [& fns]
    (fn [x] (reduce #(when %1 (%2 %1)) x (reverse fns))))

Use it like this:

  (def all (maybe-comp dec-m double-m inc-m))

It's interesting to me that the definition of maybe-comp above is
arguably simpler that the definition of maybe-m, even without
counting the machinery of 'defmonad'.  Presumably this is a hint
to how much more powerful maybe-m is than maybe-comp, and simply
shows I don't yet understand the power of monads.

--Chouser
--
-- I funded Clojure 2010, did you?  http://clojure.org/funding

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