<?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: Loops in Ocaml</title>
	<atom:link href="http://curiousprogrammer.wordpress.com/2009/05/30/ocaml-loops/feed/" rel="self" type="application/rss+xml" />
	<link>http://curiousprogrammer.wordpress.com/2009/05/30/ocaml-loops/</link>
	<description>Exploring programming languages</description>
	<lastBuildDate>Wed, 23 Dec 2009 06:05:34 +0000</lastBuildDate>
	<generator>http://wordpress.com/</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: sashang</title>
		<link>http://curiousprogrammer.wordpress.com/2009/05/30/ocaml-loops/#comment-7774</link>
		<dc:creator>sashang</dc:creator>
		<pubDate>Fri, 31 Jul 2009 10:10:23 +0000</pubDate>
		<guid isPermaLink="false">http://curiousprogrammer.wordpress.com/?p=647#comment-7774</guid>
		<description>The while, for, etc loop expressions in ocaml always have a unit return type. That&#039;s the fundamental difference between them and a tail-recursive loop construct.

# let rec loop idx = if idx == 5 then idx else loop (idx + 1);;
val loop : int -&gt; int = 
# x;;     
- : unit = ()
# let x () = for i = 0 to 5 do i done;;
Warning S: this expression should have type unit.
val x : unit -&gt; unit = 
# x ();;
- : unit = ()
# loop 0;;
- : int = 5
#</description>
		<content:encoded><![CDATA[<p>The while, for, etc loop expressions in ocaml always have a unit return type. That&#8217;s the fundamental difference between them and a tail-recursive loop construct.</p>
<p># let rec loop idx = if idx == 5 then idx else loop (idx + 1);;<br />
val loop : int -&gt; int =<br />
# x;;<br />
- : unit = ()<br />
# let x () = for i = 0 to 5 do i done;;<br />
Warning S: this expression should have type unit.<br />
val x : unit -&gt; unit =<br />
# x ();;<br />
- : unit = ()<br />
# loop 0;;<br />
- : int = 5<br />
#</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jared</title>
		<link>http://curiousprogrammer.wordpress.com/2009/05/30/ocaml-loops/#comment-7749</link>
		<dc:creator>Jared</dc:creator>
		<pubDate>Wed, 15 Jul 2009 06:10:40 +0000</pubDate>
		<guid isPermaLink="false">http://curiousprogrammer.wordpress.com/?p=647#comment-7749</guid>
		<description>Ah, the while loop.  I knew I had missed one!  I think my brain probably glossed over it when the tutorial I was reading said it was not very useful.

Thanks.</description>
		<content:encoded><![CDATA[<p>Ah, the while loop.  I knew I had missed one!  I think my brain probably glossed over it when the tutorial I was reading said it was not very useful.</p>
<p>Thanks.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Matías Giovannini</title>
		<link>http://curiousprogrammer.wordpress.com/2009/05/30/ocaml-loops/#comment-7733</link>
		<dc:creator>Matías Giovannini</dc:creator>
		<pubDate>Sun, 12 Jul 2009 02:41:48 +0000</pubDate>
		<guid isPermaLink="false">http://curiousprogrammer.wordpress.com/?p=647#comment-7733</guid>
		<description>&quot;What other types of loops are there in Ocaml?&quot;

You can also use &lt;code&gt;while&lt;code&gt;loops, with syntax &lt;code&gt;while &lt;i&gt;condition&lt;i&gt; do &lt;i&gt;statements&lt;/i&gt; done&lt;/code&gt;. The problem with imperative loops is that there is no way to break out early of them, leading to unsightly idioms like:

&lt;pre&gt;
begin try while true do
  (* calculations *)
  if &lt;i&gt;condition&lt;/i&gt; then raise Exit
done; assert false
with Exit -&gt; (* result *) end
&lt;/pre&gt;

In these cases, a tail-recursive function is more succint.</description>
		<content:encoded><![CDATA[<p>&#8220;What other types of loops are there in Ocaml?&#8221;</p>
<p>You can also use <code>while</code><code>loops, with syntax </code><code>while <i>condition</i><i> do </i><i>statements</i> done</code>. The problem with imperative loops is that there is no way to break out early of them, leading to unsightly idioms like:</p>
<pre>
begin try while true do
  (* calculations *)
  if <i>condition</i> then raise Exit
done; assert false
with Exit -&gt; (* result *) end
</pre>
<p>In these cases, a tail-recursive function is more succint.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
