On 07.01.2010, at 02:23, Steven E. Harris wrote:

That means that a monadic function has a signature like

 a -> m b

RIght.

Say that we're looking to use some "normal" functions with this
monad. Those functions may have signatures like

 a -> b

They clearly don't return the right kind of value. There must be some
way to integrate such functions without writing new wrappers around them
by hand. Is this a job for `m-fmap'?

There are various ways to construct monadic values. m-fmap is one of them, but it already requires a monadic value as input. The simplest way to construct a monadic value is m-result.

Reading the implementation, it
looks like it would take a "normal" function and allow it to call on the
basic value extracted from a monadic value.

Indeed. One way to define m-fmap is

        (defn m-fmap [f mv]
                (domonad
                        [x mv]
                        (f x)))

But note that the second value is already a monadic value.

The lift operator also sounded relevant, but, if I understand it
correctly, it converts a "normal" function to one that accepts a monadic
value and returns a monadic value.

Right. For a function of a single argument, m-lift and m-fmap are equivalent.

That's the wrong argument type to be used with bind -- which wants to call on a monadic function with a basic value -- so I don't understand when one would want to use lift. When would one be able to call on a "lifted" function? A simple example would
help.

Here is an example taken from clojure.contrib.monads.examples. The function "pairs" take a sequence of values and produces a sequences of all pairs of items in the input sequence:

(with-monad sequence-m
   (defn pairs [xs]
      ((m-lift 2 #(list %1 %2)) xs xs)))

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