On 02.11.2010, at 11:45, Sunil S Nandihalli wrote: > following is the extract from the monads example ...
It looks quite modified and no longer returns pairs! Here is the original: (with-monad sequence-m (defn pairs [xs] ((m-lift 2 #(list %1 %2)) xs xs))) > ; Another way to define pairs is through the m-seq operation. It takes > > > ; a sequence of monadic values and returns a monadic value containing > > > ; the sequence of the underlying values, obtained from chaining together > > > ; from left to right the monadic values in the sequence. > > > (with-monad sequence-m > (defn pairs [xs] > (m-seq (list xs xs)))) > > can somebody help me understand what is happening in the second one .. ? > when would it be more appropriate to use m-seq instead of m-lift .. In most real-life cases you wouldn't have that choice, as m-lift and m-seq do very different things. It's just for making pairs that either one is fine. One example for the use of m-seq is given right after the pairs example: (with-monad sequence-m (defn ntuples [n xs] (m-seq (replicate n xs)))) This is a generalization from pairs to n-tuples. You couldn't do this using m-lift applied to the list function because m-lift requires a fixed arity. Another example is given later in the example collection under "random number generators". 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