<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	>

<channel>
	<title>aaron.harnly.net &#187; blog</title>
	<atom:link href="http://harnly.net/category/blog/feed/" rel="self" type="application/rss+xml" />
	<link>http://harnly.net</link>
	<description>Sì, abbiamo un'anima. Ma è fatta di tanti piccoli robot.</description>
	<pubDate>Sat, 23 Aug 2008 04:59:59 +0000</pubDate>
	<generator>http://wordpress.org/?v=abc</generator>
	<language>en</language>
			<item>
		<title>What I&#8217;ve been up to on 2008-08-22</title>
		<link>http://harnly.net/2008/blog/autobiography/what-ive-been-up-to-on-2008-08-22/</link>
		<comments>http://harnly.net/2008/blog/autobiography/what-ive-been-up-to-on-2008-08-22/#comments</comments>
		<pubDate>Sat, 23 Aug 2008 04:59:59 +0000</pubDate>
		<dc:creator>twitterbot</dc:creator>
		
		<category><![CDATA[autobiography]]></category>

		<guid isPermaLink="false">http://harnly.net/2008/blog/autobiography/what-ive-been-up-to-on-2008-08-22/</guid>
		<description><![CDATA[
    knows exactly how many homes he owns: zero, but maybe one soon. #

]]></description>
			<content:encoded><![CDATA[<ul class="aktt_tweet_digest">
    <li>knows exactly how many homes he owns: zero, but maybe one soon. <a href="http://twitter.com/aaronharnly/statuses/895575934">#</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://harnly.net/2008/blog/autobiography/what-ive-been-up-to-on-2008-08-22/feed/</wfw:commentRss>
		</item>
		<item>
		<title>What I&#8217;ve been up to on 2008-08-19</title>
		<link>http://harnly.net/2008/blog/autobiography/what-ive-been-up-to-on-2008-08-19/</link>
		<comments>http://harnly.net/2008/blog/autobiography/what-ive-been-up-to-on-2008-08-19/#comments</comments>
		<pubDate>Wed, 20 Aug 2008 04:59:59 +0000</pubDate>
		<dc:creator>twitterbot</dc:creator>
		
		<category><![CDATA[autobiography]]></category>

		<guid isPermaLink="false">http://harnly.net/2008/blog/autobiography/what-ive-been-up-to-on-2008-08-19/</guid>
		<description><![CDATA[
    is looking to catch some phishers. #

]]></description>
			<content:encoded><![CDATA[<ul class="aktt_tweet_digest">
    <li>is looking to catch some phishers. <a href="http://twitter.com/aaronharnly/statuses/892588341">#</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://harnly.net/2008/blog/autobiography/what-ive-been-up-to-on-2008-08-19/feed/</wfw:commentRss>
		</item>
		<item>
		<title>What I&#8217;ve been up to on 2008-08-13</title>
		<link>http://harnly.net/2008/blog/autobiography/what-ive-been-up-to-on-2008-08-13/</link>
		<comments>http://harnly.net/2008/blog/autobiography/what-ive-been-up-to-on-2008-08-13/#comments</comments>
		<pubDate>Thu, 14 Aug 2008 04:59:59 +0000</pubDate>
		<dc:creator>twitterbot</dc:creator>
		
		<category><![CDATA[autobiography]]></category>

		<guid isPermaLink="false">http://harnly.net/2008/blog/autobiography/what-ive-been-up-to-on-2008-08-13/</guid>
		<description><![CDATA[
    is going meta. Writing a parser for the grammar for writing grammars for parsers. #

]]></description>
			<content:encoded><![CDATA[<ul class="aktt_tweet_digest">
    <li>is going meta. Writing a parser for the grammar for writing grammars for parsers. <a href="http://twitter.com/aaronharnly/statuses/886558359">#</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://harnly.net/2008/blog/autobiography/what-ive-been-up-to-on-2008-08-13/feed/</wfw:commentRss>
		</item>
		<item>
		<title>What I&#8217;ve been up to on 2008-08-09</title>
		<link>http://harnly.net/2008/blog/autobiography/what-ive-been-up-to-on-2008-08-09/</link>
		<comments>http://harnly.net/2008/blog/autobiography/what-ive-been-up-to-on-2008-08-09/#comments</comments>
		<pubDate>Sun, 10 Aug 2008 04:59:59 +0000</pubDate>
		<dc:creator>twitterbot</dc:creator>
		
		<category><![CDATA[autobiography]]></category>

		<guid isPermaLink="false">http://harnly.net/2008/blog/autobiography/what-ive-been-up-to-on-2008-08-09/</guid>
		<description><![CDATA[
    couldn&#8217;t find guar gum at the grocery store. Maybe a little spit &#38; plaster of paris will work? #

]]></description>
			<content:encoded><![CDATA[<ul class="aktt_tweet_digest">
    <li>couldn&#8217;t find guar gum at the grocery store. Maybe a little spit &amp; plaster of paris will work? <a href="http://twitter.com/aaronharnly/statuses/882541528">#</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://harnly.net/2008/blog/autobiography/what-ive-been-up-to-on-2008-08-09/feed/</wfw:commentRss>
		</item>
		<item>
		<title>What I&#8217;ve been up to on 2008-08-06</title>
		<link>http://harnly.net/2008/blog/autobiography/what-ive-been-up-to-on-2008-08-06/</link>
		<comments>http://harnly.net/2008/blog/autobiography/what-ive-been-up-to-on-2008-08-06/#comments</comments>
		<pubDate>Thu, 07 Aug 2008 04:59:59 +0000</pubDate>
		<dc:creator>twitterbot</dc:creator>
		
		<category><![CDATA[autobiography]]></category>

		<guid isPermaLink="false">http://harnly.net/2008/blog/autobiography/what-ive-been-up-to-on-2008-08-06/</guid>
		<description><![CDATA[
    wants to ride in an A380 just for the Tailcam. #

]]></description>
			<content:encoded><![CDATA[<ul class="aktt_tweet_digest">
    <li>wants to ride in an A380 just for the Tailcam. <a href="http://twitter.com/aaronharnly/statuses/879611794">#</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://harnly.net/2008/blog/autobiography/what-ive-been-up-to-on-2008-08-06/feed/</wfw:commentRss>
		</item>
		<item>
		<title>What I&#8217;ve been up to on 2008-08-04</title>
		<link>http://harnly.net/2008/blog/autobiography/what-ive-been-up-to-on-2008-08-04/</link>
		<comments>http://harnly.net/2008/blog/autobiography/what-ive-been-up-to-on-2008-08-04/#comments</comments>
		<pubDate>Tue, 05 Aug 2008 04:59:59 +0000</pubDate>
		<dc:creator>twitterbot</dc:creator>
		
		<category><![CDATA[autobiography]]></category>

		<guid isPermaLink="false">http://harnly.net/2008/blog/autobiography/what-ive-been-up-to-on-2008-08-04/</guid>
		<description><![CDATA[
    wondering whether cherries would be as delicious if they were the size of plums. Would they be too strong? Or the best thing ever? #

]]></description>
			<content:encoded><![CDATA[<ul class="aktt_tweet_digest">
    <li>wondering whether cherries would be as delicious if they were the size of plums. Would they be too strong? Or the best thing ever? <a href="http://twitter.com/aaronharnly/statuses/877544742">#</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://harnly.net/2008/blog/autobiography/what-ive-been-up-to-on-2008-08-04/feed/</wfw:commentRss>
		</item>
		<item>
		<title>What I&#8217;ve been up to on 2008-08-01</title>
		<link>http://harnly.net/2008/blog/autobiography/what-ive-been-up-to-on-2008-08-01/</link>
		<comments>http://harnly.net/2008/blog/autobiography/what-ive-been-up-to-on-2008-08-01/#comments</comments>
		<pubDate>Sat, 02 Aug 2008 04:59:59 +0000</pubDate>
		<dc:creator>twitterbot</dc:creator>
		
		<category><![CDATA[autobiography]]></category>

		<guid isPermaLink="false">http://harnly.net/2008/blog/autobiography/what-ive-been-up-to-on-2008-08-01/</guid>
		<description><![CDATA[
    so happy there&#8217;s going to be an official &#8220;garfield minus garfield&#8221; book. Jim Davis must be cooler than I&#8217;ve given him credit for. #

]]></description>
			<content:encoded><![CDATA[<ul class="aktt_tweet_digest">
    <li>so happy there&#8217;s going to be an official &#8220;garfield minus garfield&#8221; book. Jim Davis must be cooler than I&#8217;ve given him credit for. <a href="http://twitter.com/aaronharnly/statuses/874662735">#</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://harnly.net/2008/blog/autobiography/what-ive-been-up-to-on-2008-08-01/feed/</wfw:commentRss>
		</item>
		<item>
		<title>What I&#8217;ve been up to on 2008-07-22</title>
		<link>http://harnly.net/2008/blog/autobiography/what-ive-been-up-to-on-2008-07-22/</link>
		<comments>http://harnly.net/2008/blog/autobiography/what-ive-been-up-to-on-2008-07-22/#comments</comments>
		<pubDate>Wed, 23 Jul 2008 04:59:59 +0000</pubDate>
		<dc:creator>twitterbot</dc:creator>
		
		<category><![CDATA[autobiography]]></category>

		<guid isPermaLink="false">http://harnly.net/2008/blog/autobiography/what-ive-been-up-to-on-2008-07-22/</guid>
		<description><![CDATA[
    is wrestling with cyclic reference errors, and feels like a cyclic reference error himself. #

]]></description>
			<content:encoded><![CDATA[<ul class="aktt_tweet_digest">
    <li>is wrestling with cyclic reference errors, and feels like a cyclic reference error himself. <a href="http://twitter.com/aaronharnly/statuses/865305335">#</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://harnly.net/2008/blog/autobiography/what-ive-been-up-to-on-2008-07-22/feed/</wfw:commentRss>
		</item>
		<item>
		<title>What I&#8217;ve been up to on 2008-07-19</title>
		<link>http://harnly.net/2008/blog/autobiography/what-ive-been-up-to-on-2008-07-19/</link>
		<comments>http://harnly.net/2008/blog/autobiography/what-ive-been-up-to-on-2008-07-19/#comments</comments>
		<pubDate>Sun, 20 Jul 2008 04:59:59 +0000</pubDate>
		<dc:creator>twitterbot</dc:creator>
		
		<category><![CDATA[autobiography]]></category>

		<guid isPermaLink="false">http://harnly.net/2008/blog/autobiography/what-ive-been-up-to-on-2008-07-19/</guid>
		<description><![CDATA[
    has been watching 90 minutes of 30 Rock every night. I think this TV thing might catch on. #

]]></description>
			<content:encoded><![CDATA[<ul class="aktt_tweet_digest">
    <li>has been watching 90 minutes of 30 Rock every night. I think this TV thing might catch on. <a href="http://twitter.com/aaronharnly/statuses/862814342">#</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://harnly.net/2008/blog/autobiography/what-ive-been-up-to-on-2008-07-19/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Lazy vals with implicit parameters</title>
		<link>http://harnly.net/2008/blog/geek/lang/scala/lazy-vals-with-implicit-parameters/</link>
		<comments>http://harnly.net/2008/blog/geek/lang/scala/lazy-vals-with-implicit-parameters/#comments</comments>
		<pubDate>Thu, 17 Jul 2008 15:04:54 +0000</pubDate>
		<dc:creator>aaronharnly</dc:creator>
		
		<category><![CDATA[scala]]></category>

		<guid isPermaLink="false">http://harnly.net/?p=176</guid>
		<description><![CDATA[Lazy vals were an excellent addition to Scala 2.6.0. They allow you to defer calculation of a value until it is actually needed, after which the calculated value is cached. 

Unfortunately, this doesn&#8217;t play so well with another wonderful Scala feature &#8212; implicit parameters. It&#8217;s often the case that you&#8217;ll want to defer resolution of an [...]]]></description>
			<content:encoded><![CDATA[<p>Lazy vals were an excellent addition to <a href="http://www.scala-lang.org/docu/changelog.html#v2.6.0">Scala 2.6.0</a>. They allow you to defer calculation of a value until it is actually needed, after which the calculated value is cached. </p>

<p>Unfortunately, this doesn&#8217;t play so well with another wonderful Scala feature &mdash; <a href="http://www.scala-lang.org/intro/implicit.html">implicit parameters</a>. It&#8217;s often the case that you&#8217;ll want to defer resolution of an implicit until a method call, rather than in the scope of object creation. But lazy values cannot take any parameters, implicit or otherwise &mdash; so it seems you&#8217;re stuck.</p>

<p>Memoized to the rescue! This is a simple helper class that takes care of the caching of a result. Where you might have had the following method with an implicit parameter:</p>


<div class="wp_syntax"><div class="code"><pre class="scala"><span style="color: #0000ff; font-weight: bold;">def</span> foo<span style="color: #F78811;">&#40;</span><span style="color: #0000ff; font-weight: bold;">implicit</span> bar<span style="color: #000080;">:</span> Bar<span style="color: #F78811;">&#41;</span><span style="color: #000080;">:</span> ResultType <span style="color: #000080;">=</span> <span style="color: #F78811;">&#123;</span> ... <span style="color: #F78811;">&#125;</span></pre></div></div>


<p>you instead write the following:</p>


<div class="wp_syntax"><div class="code"><pre class="scala"><span style="color: #0000ff; font-weight: bold;">private</span> <span style="color: #0000ff; font-weight: bold;">var</span> <span style="color: #000080;">_</span>foo <span style="color: #000080;">=</span> Memoized<span style="color: #F78811;">&#91;</span>ResultType<span style="color: #F78811;">&#93;</span>
<span style="color: #0000ff; font-weight: bold;">def</span> foo<span style="color: #F78811;">&#40;</span><span style="color: #0000ff; font-weight: bold;">implicit</span> bar<span style="color: #000080;">:</span> Bar<span style="color: #F78811;">&#41;</span> <span style="color: #000080;">=</span> <span style="color: #000080;">_</span>foo or <span style="color: #F78811;">&#123;</span> ... <span style="color: #F78811;">&#125;</span></pre></div></div>


<p>(complete source below the fold)
<span id="more-176"></span></p>

<p>That&#8217;s it; nothing fancy. This is not a true memoization solution for a function that takes a parameter &mdash; check out <a href="http://projects.workingmouse.com/public/scalaz/trunk/src/main/scalaz/memo/">the memo package</a> in <a href="http://wiki.workingmouse.com/index.php/Scalaz">Scalaz</a> for that. But I&#8217;ve found it handy, and you might too.</p>


<div class="wp_syntax"><div class="code"><pre class="scala"><span style="color: #0000ff; font-weight: bold;">class</span> Memoized<span style="color: #F78811;">&#91;</span>T<span style="color: #F78811;">&#93;</span> <span style="color: #F78811;">&#123;</span>
	<span style="color: #0000ff; font-weight: bold;">private</span> <span style="color: #0000ff; font-weight: bold;">var</span> value<span style="color: #000080;">:</span> Option<span style="color: #F78811;">&#91;</span>T<span style="color: #F78811;">&#93;</span> <span style="color: #000080;">=</span> None
	<span style="color: #0000ff; font-weight: bold;">def</span> isEmpty <span style="color: #000080;">=</span> value.<span style="color: #000000;">isEmpty</span>
	<span style="color: #0000ff; font-weight: bold;">def</span> isDefined <span style="color: #000080;">=</span> <span style="color: #000080;">!</span> isEmpty
	<span style="color: #0000ff; font-weight: bold;">def</span> get<span style="color: #000080;">:</span> T <span style="color: #000080;">=</span> value.<span style="color: #000000;">get</span>
	<span style="color: #0000ff; font-weight: bold;">def</span> set<span style="color: #F78811;">&#40;</span>newValue<span style="color: #000080;">:</span> T<span style="color: #F78811;">&#41;</span> <span style="color: #F78811;">&#123;</span> value <span style="color: #000080;">=</span> Some<span style="color: #F78811;">&#40;</span>newValue<span style="color: #F78811;">&#41;</span> <span style="color: #F78811;">&#125;</span>
	<span style="color: #0000ff; font-weight: bold;">def</span> getOrSet<span style="color: #F78811;">&#40;</span> newValue<span style="color: #000080;">:</span> <span style="color: #000080;">=&gt;</span> T<span style="color: #F78811;">&#41;</span><span style="color: #000080;">:</span> T <span style="color: #000080;">=</span> <span style="color: #0000ff; font-weight: bold;">if</span> <span style="color: #F78811;">&#40;</span>isDefined<span style="color: #F78811;">&#41;</span> get <span style="color: #0000ff; font-weight: bold;">else</span> <span style="color: #F78811;">&#123;</span>
		set<span style="color: #F78811;">&#40;</span>newValue<span style="color: #F78811;">&#41;</span>
		get
	<span style="color: #F78811;">&#125;</span>
	<span style="color: #0000ff; font-weight: bold;">def</span> or<span style="color: #F78811;">&#40;</span> newValue<span style="color: #000080;">:</span> <span style="color: #000080;">=&gt;</span> T<span style="color: #F78811;">&#41;</span><span style="color: #000080;">:</span> T <span style="color: #000080;">=</span> getOrSet<span style="color: #F78811;">&#40;</span>newValue<span style="color: #F78811;">&#41;</span>
	<span style="color: #0000ff; font-weight: bold;">override</span> <span style="color: #0000ff; font-weight: bold;">def</span> toString <span style="color: #000080;">=</span> value.<span style="color: #000000;">toString</span>
<span style="color: #F78811;">&#125;</span>
&nbsp;
<span style="color: #0000ff; font-weight: bold;">object</span> Memoized <span style="color: #F78811;">&#123;</span>
	<span style="color: #0000ff; font-weight: bold;">def</span> apply<span style="color: #F78811;">&#91;</span>T<span style="color: #F78811;">&#93;</span> <span style="color: #000080;">=</span> <span style="color: #0000ff; font-weight: bold;">new</span> Memoized<span style="color: #F78811;">&#91;</span>T<span style="color: #F78811;">&#93;</span>
<span style="color: #F78811;">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://harnly.net/2008/blog/geek/lang/scala/lazy-vals-with-implicit-parameters/feed/</wfw:commentRss>
		</item>
	</channel>
</rss>

<!-- Dynamic Page Served (once) in 0.958 seconds -->
