<?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/"
	
	>
<channel>
	<title>Comments on: Details for non-strict memoization, part 1</title>
	<atom:link href="http://conal.net/blog/posts/details-for-nonstrict-memoization-part-1/feed" rel="self" type="application/rss+xml" />
	<link>http://conal.net/blog/posts/details-for-nonstrict-memoization-part-1</link>
	<description>Inspirations &#38; experiments, mainly about denotative/functional programming in Haskell</description>
	<lastBuildDate>Sat, 26 Sep 2020 21:06:12 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=4.1.17</generator>
	<item>
		<title>By: conal</title>
		<link>http://conal.net/blog/posts/details-for-nonstrict-memoization-part-1#comment-650</link>
		<dc:creator><![CDATA[conal]]></dc:creator>
		<pubDate>Tue, 27 Jul 2010 02:54:29 +0000</pubDate>
		<guid isPermaLink="false">http://conal.net/blog/?p=131#comment-650</guid>
		<description><![CDATA[&lt;p&gt;Hi Felipe,&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;How do these lub’s affect performance in practice? IIRC, each of them creates two threads and uses some synchronizations between them.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The performance depends a lot on the implementation of &lt;code&gt;unamb&lt;/code&gt; and &lt;code&gt;lub&lt;/code&gt; and their susceptibility to compiler optimization.  The most naive implementation I know of works as you mentioned: each &lt;code&gt;unamb&lt;/code&gt; starts two threads, with an &lt;code&gt;MVar&lt;/code&gt; to coordinate them.  However, the threads can be avoided when (a) either argument is already evaluated to a non-⊥ form or (b) either argument is known to be ⊥ (e.g., typically an error of some sort, including evaluating &lt;code&gt;undefined&lt;/code&gt; or a failed pattern-match).  In other words,&lt;/p&gt;

&lt;p&gt;&lt;div&gt;
&lt;pre class=&quot;haskell&quot;&gt;a ⊔ ⊥ ≡ a
⊥ ⊔ b ≡ b
&#160;
a `unamb` ⊥ ≡ a
⊥ `unamb` b ≡ b
&#160;
a `unamb` b ≡ a  &lt;span style=&quot;color: #050; font-weight: bold;&quot;&gt;if&lt;/span&gt;  a ≠ ⊥
a `unamb` b ≡ b  &lt;span style=&quot;color: #050; font-weight: bold;&quot;&gt;if&lt;/span&gt;  b ≠ ⊥&lt;/pre&gt;
&lt;/div&gt;&lt;/p&gt;

&lt;p&gt;All with the proviso the preconditions of &lt;code&gt;unamb&lt;/code&gt; or &lt;code&gt;lub&lt;/code&gt; are satisfied.&lt;/p&gt;

&lt;p&gt;I&#039;m more interested in the soundness and usefulness of uses of &lt;code&gt;lub&lt;/code&gt; than its performance right now.
Once there are compelling demonstrations of both, then there will be enough motivation to make high-performance implementations.
Great performance might require some hacking inside the language run-time system.
This same evolution occurred for lazy evaluation.&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;Are there cases where the non-strictness would outperform the performance penalty?&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Yes, since non-strictness sometimes replaces non-termination with termination -- a pretty impressive speed-up.&lt;/p&gt;

&lt;p&gt;Seriously, though, like laziness, lub-based programming is about correctness, simple &amp; rigorous reasoning, and modularity, as well as performance.&lt;/p&gt;
]]></description>
		<content:encoded><![CDATA[<p>Hi Felipe,</p>

<blockquote>
  <p>How do these lub’s affect performance in practice? IIRC, each of them creates two threads and uses some synchronizations between them.</p>
</blockquote>

<p>The performance depends a lot on the implementation of <code>unamb</code> and <code>lub</code> and their susceptibility to compiler optimization.  The most naive implementation I know of works as you mentioned: each <code>unamb</code> starts two threads, with an <code>MVar</code> to coordinate them.  However, the threads can be avoided when (a) either argument is already evaluated to a non-⊥ form or (b) either argument is known to be ⊥ (e.g., typically an error of some sort, including evaluating <code>undefined</code> or a failed pattern-match).  In other words,</p>

<p><div>
<pre class="haskell">a ⊔ ⊥ ≡ a
⊥ ⊔ b ≡ b
&nbsp;
a `unamb` ⊥ ≡ a
⊥ `unamb` b ≡ b
&nbsp;
a `unamb` b ≡ a  <span style="color: #050; font-weight: bold;">if</span>  a ≠ ⊥
a `unamb` b ≡ b  <span style="color: #050; font-weight: bold;">if</span>  b ≠ ⊥</pre>
</div></p>

<p>All with the proviso the preconditions of <code>unamb</code> or <code>lub</code> are satisfied.</p>

<p>I&#8217;m more interested in the soundness and usefulness of uses of <code>lub</code> than its performance right now.
Once there are compelling demonstrations of both, then there will be enough motivation to make high-performance implementations.
Great performance might require some hacking inside the language run-time system.
This same evolution occurred for lazy evaluation.</p>

<blockquote>
  <p>Are there cases where the non-strictness would outperform the performance penalty?</p>
</blockquote>

<p>Yes, since non-strictness sometimes replaces non-termination with termination &#8212; a pretty impressive speed-up.</p>

<p>Seriously, though, like laziness, lub-based programming is about correctness, simple &amp; rigorous reasoning, and modularity, as well as performance.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Felipe Lessa</title>
		<link>http://conal.net/blog/posts/details-for-nonstrict-memoization-part-1#comment-649</link>
		<dc:creator><![CDATA[Felipe Lessa]]></dc:creator>
		<pubDate>Tue, 27 Jul 2010 01:57:27 +0000</pubDate>
		<guid isPermaLink="false">http://conal.net/blog/?p=131#comment-649</guid>
		<description><![CDATA[&lt;p&gt;How do these lub&#039;s affect performance in practice?  IIRC, each of them creates two threads and uses some synchronizations between them.  Are there cases where the non-strictness would outperform the performance penalty?&lt;/p&gt;

&lt;p&gt;Cheers! =)&lt;/p&gt;
]]></description>
		<content:encoded><![CDATA[<p>How do these lub&#8217;s affect performance in practice?  IIRC, each of them creates two threads and uses some synchronizations between them.  Are there cases where the non-strictness would outperform the performance penalty?</p>

<p>Cheers! =)</p>
]]></content:encoded>
	</item>
</channel>
</rss>
