<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
		>
<channel>
	<title>Comments on: A monad tutorial for Clojure programmers (part 3)</title>
	<atom:link href="http://onclojure.com/2009/03/23/a-monad-tutorial-for-clojure-programmers-part-3/feed/" rel="self" type="application/rss+xml" />
	<link>http://onclojure.com/2009/03/23/a-monad-tutorial-for-clojure-programmers-part-3/</link>
	<description>A blog about everything Clojure</description>
	<lastBuildDate>Wed, 13 Jul 2011 20:11:47 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
	<item>
		<title>By: Kurt Harriger</title>
		<link>http://onclojure.com/2009/03/23/a-monad-tutorial-for-clojure-programmers-part-3/#comment-153</link>
		<dc:creator><![CDATA[Kurt Harriger]]></dc:creator>
		<pubDate>Tue, 21 Dec 2010 17:24:21 +0000</pubDate>
		<guid isPermaLink="false">http://onclojure.com/?p=33#comment-153</guid>
		<description><![CDATA[I too am interested in the monadic implementation of fib.  Basically my understanding is that a lazy sequence is a continuation monad where the head is the current result and tail represents the future computation.

F# uses sequence monads to construct IEnumerable.  As you pointed out there is some compiler magic that rearranges the statements into monadic expressions (http://blogs.msdn.com/b/dsyme/archive/2007/09/22/some-details-on-f-computation-expressions-aka-monadic-or-workflow-syntax.aspx).  In clojure I would assume one could do this same transformation with a macro.  

So back to the question of why?  Although this seems unnecessary in a clojure where lazy sequences accomplish the same thing. I&#039;m still wondering if lazy-seq may be the bridge between, rather than a replacement for, the monadic representation. 

Here is a web application where the author used fill-queue to convert the web server into a sequence generator rather than a event dispatcher.  http://infolace.blogspot.com/2009/08/simple-webhooks-with-clojure-and-ring.html.  

Using the same technique I could write fib in an imperative style.  
(def fib (fill-queue (fn loop [fill] [a 0 b 1] (fill a) (recur b (+ a b)))))

However the above uses another thread which blocks when the queue is full, in some cases this concurrent computation may be desirable, but it probably isn&#039;t desirable to dedicate a thread to each computation.

In F# events can be composed, filtered and mapped just as a sequence of events rather than traditional event handlers (http://codebetter.com/matthewpodwysocki/2009/08/11/first-class-composable-events-in-f/) which makes the code very expressive.  

Here is a clojure web framework that uses a continuation monad to preserve the state of a web application http://intensivesystems.net/tutorials/cont_m_web.html.  In this case continuations rather than separate threads are used to maintain state.  Could this be implemented as a lazy sequence instead?  In F# asynchronous workflows are also implemented via monads.  Some C# developers are using IEnumerable and linq to develop async workflows (http://tomasp.net/blog/csharp-async.aspx). So I think the answer is yes, but the real question I think is would using a lazy sequence make the code easier or more difficult to understand, write and maintain?  

I think applications might be written as async workflows, and instead of using event handlers they pull a sequence of events and maintain state between events in local variables (sate monad).  This would have the feel of stdin/stdout in unix, but rather than the workflow blocking on output and requiring a dedicated thread a continuation could be used to externalize the choice of threading model.]]></description>
		<content:encoded><![CDATA[<p>I too am interested in the monadic implementation of fib.  Basically my understanding is that a lazy sequence is a continuation monad where the head is the current result and tail represents the future computation.</p>
<p>F# uses sequence monads to construct IEnumerable.  As you pointed out there is some compiler magic that rearranges the statements into monadic expressions (<a href="http://blogs.msdn.com/b/dsyme/archive/2007/09/22/some-details-on-f-computation-expressions-aka-monadic-or-workflow-syntax.aspx" rel="nofollow">http://blogs.msdn.com/b/dsyme/archive/2007/09/22/some-details-on-f-computation-expressions-aka-monadic-or-workflow-syntax.aspx</a>).  In clojure I would assume one could do this same transformation with a macro.  </p>
<p>So back to the question of why?  Although this seems unnecessary in a clojure where lazy sequences accomplish the same thing. I&#8217;m still wondering if lazy-seq may be the bridge between, rather than a replacement for, the monadic representation. </p>
<p>Here is a web application where the author used fill-queue to convert the web server into a sequence generator rather than a event dispatcher.  <a href="http://infolace.blogspot.com/2009/08/simple-webhooks-with-clojure-and-ring.html" rel="nofollow">http://infolace.blogspot.com/2009/08/simple-webhooks-with-clojure-and-ring.html</a>.  </p>
<p>Using the same technique I could write fib in an imperative style.<br />
(def fib (fill-queue (fn loop [fill] [a 0 b 1] (fill a) (recur b (+ a b)))))</p>
<p>However the above uses another thread which blocks when the queue is full, in some cases this concurrent computation may be desirable, but it probably isn&#8217;t desirable to dedicate a thread to each computation.</p>
<p>In F# events can be composed, filtered and mapped just as a sequence of events rather than traditional event handlers (<a href="http://codebetter.com/matthewpodwysocki/2009/08/11/first-class-composable-events-in-f/" rel="nofollow">http://codebetter.com/matthewpodwysocki/2009/08/11/first-class-composable-events-in-f/</a>) which makes the code very expressive.  </p>
<p>Here is a clojure web framework that uses a continuation monad to preserve the state of a web application <a href="http://intensivesystems.net/tutorials/cont_m_web.html" rel="nofollow">http://intensivesystems.net/tutorials/cont_m_web.html</a>.  In this case continuations rather than separate threads are used to maintain state.  Could this be implemented as a lazy sequence instead?  In F# asynchronous workflows are also implemented via monads.  Some C# developers are using IEnumerable and linq to develop async workflows (<a href="http://tomasp.net/blog/csharp-async.aspx" rel="nofollow">http://tomasp.net/blog/csharp-async.aspx</a>). So I think the answer is yes, but the real question I think is would using a lazy sequence make the code easier or more difficult to understand, write and maintain?  </p>
<p>I think applications might be written as async workflows, and instead of using event handlers they pull a sequence of events and maintain state between events in local variables (sate monad).  This would have the feel of stdin/stdout in unix, but rather than the workflow blocking on output and requiring a dedicated thread a continuation could be used to externalize the choice of threading model.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: khinsen</title>
		<link>http://onclojure.com/2009/03/23/a-monad-tutorial-for-clojure-programmers-part-3/#comment-139</link>
		<dc:creator><![CDATA[khinsen]]></dc:creator>
		<pubDate>Fri, 29 Oct 2010 12:37:24 +0000</pubDate>
		<guid isPermaLink="false">http://onclojure.com/?p=33#comment-139</guid>
		<description><![CDATA[The typos are fixed. Thanks for the feedback! Unfortunately all my applications are either throwaway code (not very presentable) or somewhat confidential.]]></description>
		<content:encoded><![CDATA[<p>The typos are fixed. Thanks for the feedback! Unfortunately all my applications are either throwaway code (not very presentable) or somewhat confidential.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jacek Laskowski</title>
		<link>http://onclojure.com/2009/03/23/a-monad-tutorial-for-clojure-programmers-part-3/#comment-137</link>
		<dc:creator><![CDATA[Jacek Laskowski]]></dc:creator>
		<pubDate>Thu, 28 Oct 2010 10:50:47 +0000</pubDate>
		<guid isPermaLink="false">http://onclojure.com/?p=33#comment-137</guid>
		<description><![CDATA[Read it again and spot 2 typos:

&lt;i&gt;rest of to the domonad form&lt;/i&gt; should become &lt;i&gt;rest of the domonad form&lt;/i&gt; (&#039;to&#039; removed)

&lt;i&gt;used that is has itself&lt;/i&gt; should become &lt;i&gt;used that has itself&lt;/i&gt; (&#039;is&#039; removed)

Thanks for the article and the others! They&#039;re very mind-blowing and simply awesome. I wish you&#039;d share when/how you used the library so I&#039;d follow along and understand monads better.]]></description>
		<content:encoded><![CDATA[<p>Read it again and spot 2 typos:</p>
<p><i>rest of to the domonad form</i> should become <i>rest of the domonad form</i> (&#8216;to&#8217; removed)</p>
<p><i>used that is has itself</i> should become <i>used that has itself</i> (&#8216;is&#8217; removed)</p>
<p>Thanks for the article and the others! They&#8217;re very mind-blowing and simply awesome. I wish you&#8217;d share when/how you used the library so I&#8217;d follow along and understand monads better.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jacek Laskowski</title>
		<link>http://onclojure.com/2009/03/23/a-monad-tutorial-for-clojure-programmers-part-3/#comment-136</link>
		<dc:creator><![CDATA[Jacek Laskowski]]></dc:creator>
		<pubDate>Mon, 18 Oct 2010 12:05:18 +0000</pubDate>
		<guid isPermaLink="false">http://onclojure.com/?p=33#comment-136</guid>
		<description><![CDATA[Just noticed - shouldn&#039;t 

(domonad sequence
  [a (range 5)
   :when (odd? a)]
  (* 2 a))

use sequence-m?]]></description>
		<content:encoded><![CDATA[<p>Just noticed &#8211; shouldn&#8217;t </p>
<p>(domonad sequence<br />
  [a (range 5)<br />
   :when (odd? a)]<br />
  (* 2 a))</p>
<p>use sequence-m?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: khinsen</title>
		<link>http://onclojure.com/2009/03/23/a-monad-tutorial-for-clojure-programmers-part-3/#comment-131</link>
		<dc:creator><![CDATA[khinsen]]></dc:creator>
		<pubDate>Thu, 09 Sep 2010 17:07:51 +0000</pubDate>
		<guid isPermaLink="false">http://onclojure.com/?p=33#comment-131</guid>
		<description><![CDATA[Python implements generators (and thus yield) using a lot of magic going on behind the scenes. Generators should be considered a special control structure in Python. Clojure has different functional control structures that cover most practical situations where Python programmers would use generators. I don&#039;t see any reason why it would be impractical to introduce generators into Clojure, but I don&#039;t see any good reason for doing so either.]]></description>
		<content:encoded><![CDATA[<p>Python implements generators (and thus yield) using a lot of magic going on behind the scenes. Generators should be considered a special control structure in Python. Clojure has different functional control structures that cover most practical situations where Python programmers would use generators. I don&#8217;t see any reason why it would be impractical to introduce generators into Clojure, but I don&#8217;t see any good reason for doing so either.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: khinsen</title>
		<link>http://onclojure.com/2009/03/23/a-monad-tutorial-for-clojure-programmers-part-3/#comment-130</link>
		<dc:creator><![CDATA[khinsen]]></dc:creator>
		<pubDate>Thu, 09 Sep 2010 16:58:49 +0000</pubDate>
		<guid isPermaLink="false">http://onclojure.com/?p=33#comment-130</guid>
		<description><![CDATA[I prefer the similarity that (get s key) has to (assoc s key val), that&#039;s all!]]></description>
		<content:encoded><![CDATA[<p>I prefer the similarity that (get s key) has to (assoc s key val), that&#8217;s all!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jacek Laskowski</title>
		<link>http://onclojure.com/2009/03/23/a-monad-tutorial-for-clojure-programmers-part-3/#comment-129</link>
		<dc:creator><![CDATA[Jacek Laskowski]]></dc:creator>
		<pubDate>Thu, 09 Sep 2010 16:27:27 +0000</pubDate>
		<guid isPermaLink="false">http://onclojure.com/?p=33#comment-129</guid>
		<description><![CDATA[Why do you use (get s key) in set-val not (key s)?]]></description>
		<content:encoded><![CDATA[<p>Why do you use (get s key) in set-val not (key s)?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: RosenK</title>
		<link>http://onclojure.com/2009/03/23/a-monad-tutorial-for-clojure-programmers-part-3/#comment-128</link>
		<dc:creator><![CDATA[RosenK]]></dc:creator>
		<pubDate>Thu, 09 Sep 2010 15:35:27 +0000</pubDate>
		<guid isPermaLink="false">http://onclojure.com/?p=33#comment-128</guid>
		<description><![CDATA[Why yield is practical in Python but is not practical in Clojure? Why there is any difference?]]></description>
		<content:encoded><![CDATA[<p>Why yield is practical in Python but is not practical in Clojure? Why there is any difference?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: khinsen</title>
		<link>http://onclojure.com/2009/03/23/a-monad-tutorial-for-clojure-programmers-part-3/#comment-124</link>
		<dc:creator><![CDATA[khinsen]]></dc:creator>
		<pubDate>Fri, 03 Sep 2010 14:37:38 +0000</pubDate>
		<guid isPermaLink="false">http://onclojure.com/?p=33#comment-124</guid>
		<description><![CDATA[I think I understand better now what you are looking for, but I am not sure monads are the right approach. Remember that monads are a technique for combining computational steps that need to take into account some specific effect. The monad is designed to take care of the effect. Which effect (and thus which monad) would you want to have applied to the generation of Fibonacci numbers?

The only monad I can see as of some relevance to your example is the continuation monad. You could write all your computations in continuation-passing style and use the continuation monad to combine them. You could then implement generator-like constructs through continuations. However, this looks way too complicated to be of any practical interest.]]></description>
		<content:encoded><![CDATA[<p>I think I understand better now what you are looking for, but I am not sure monads are the right approach. Remember that monads are a technique for combining computational steps that need to take into account some specific effect. The monad is designed to take care of the effect. Which effect (and thus which monad) would you want to have applied to the generation of Fibonacci numbers?</p>
<p>The only monad I can see as of some relevance to your example is the continuation monad. You could write all your computations in continuation-passing style and use the continuation monad to combine them. You could then implement generator-like constructs through continuations. However, this looks way too complicated to be of any practical interest.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: RosenK</title>
		<link>http://onclojure.com/2009/03/23/a-monad-tutorial-for-clojure-programmers-part-3/#comment-123</link>
		<dc:creator><![CDATA[RosenK]]></dc:creator>
		<pubDate>Fri, 03 Sep 2010 09:16:49 +0000</pubDate>
		<guid isPermaLink="false">http://onclojure.com/?p=33#comment-123</guid>
		<description><![CDATA[I&#039;m quite disappointed from your answer because I&#039;m convinced that something similar to the Python&#039;s yield could be implemented in clojure with monads (but I don&#039;t know how and that was the whole point of my question). In this way the clojure&#039;s code would be much more similar to the Python&#039;s approach. I&#039;m not looking in making clojure a python like but I&#039;m interested in how the monad concepts are used in the different languages. I&#039;m quite sure that the fibnacci solution that you gave is probably better that anything with monads - but that was not the point.
To paraphrase I&#039;m looking for some sort of generalization with monads of the above code that will emerge a &#039;yield&#039; in the clojure&#039;s world.]]></description>
		<content:encoded><![CDATA[<p>I&#8217;m quite disappointed from your answer because I&#8217;m convinced that something similar to the Python&#8217;s yield could be implemented in clojure with monads (but I don&#8217;t know how and that was the whole point of my question). In this way the clojure&#8217;s code would be much more similar to the Python&#8217;s approach. I&#8217;m not looking in making clojure a python like but I&#8217;m interested in how the monad concepts are used in the different languages. I&#8217;m quite sure that the fibnacci solution that you gave is probably better that anything with monads &#8211; but that was not the point.<br />
To paraphrase I&#8217;m looking for some sort of generalization with monads of the above code that will emerge a &#8216;yield&#8217; in the clojure&#8217;s world.</p>
]]></content:encoded>
	</item>
</channel>
</rss>

