<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-7480826096025842182</id><updated>2011-12-08T18:03:42.729+02:00</updated><category term='quote'/><category term='scala'/><category term='implicits'/><title type='text'>Scalada - all about Scala</title><subtitle type='html'></subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://scalada.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7480826096025842182/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://scalada.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Henrik Huttunen</name><uri>http://www.blogger.com/profile/01845345214435219727</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://2.bp.blogspot.com/_0wWQ_NzU8Fs/S5adjK4NVpI/AAAAAAAAAB8/d6BDyZALfyo/S220/naama.JPG'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>9</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-7480826096025842182.post-5156409097392859861</id><published>2010-03-10T20:59:00.005+02:00</published><updated>2010-03-10T21:15:35.200+02:00</updated><title type='text'>Constructing list by functionally threading state between user inputs</title><content type='html'>Ah, feels good to hack a bit of Scala after a while. A friend of mine was thinking about getting more lightweight syntax for list creation and I had urge to try something out. A simple way would be to create an implicit def that would lift a value to list:&lt;br /&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="background-color: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;span class="Apple-style-span"&gt;&lt;span class="Apple-style-span" style="background-color: #f3f3f3;"&gt;implicit def valueToList[a](value: a) = List(value)&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Now you could have expressions like&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&lt;span class="Apple-style-span" style="background-color: #f3f3f3;"&gt; &amp;nbsp;&lt;/span&gt;&lt;span class="Apple-style-span"&gt;&lt;span class="Apple-style-span" style="background-color: #f3f3f3;"&gt;5 :: 3 (of type List[Int])&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;But just for fun I tried different approach that uses functions as intermediate values. After playing with it a while I ended up with a couple of cute trait/classes. They deal with order of evaluation so that one can for example ask user for some input, and decide should input be accepted or just ask for another. Here's what one toy use case looks like:&lt;br /&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="background-color: #f3f3f3;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span class="Apple-style-span"&gt;&lt;span class="Apple-style-span" style="background-color: #f3f3f3;"&gt;&amp;nbsp;val result =&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;&lt;span class="Apple-style-span"&gt;&lt;span class="Apple-style-span" style="background-color: #f3f3f3;"&gt; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span"&gt;&lt;span class="Apple-style-span" style="background-color: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;Builder.create[String]&amp;nbsp;$&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;&lt;span class="Apple-style-span"&gt;&lt;span class="Apple-style-span" style="background-color: #f3f3f3;"&gt;   &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span"&gt;&lt;span class="Apple-style-span" style="background-color: #f3f3f3;"&gt; &amp;nbsp;ask ("Favourite number?", _ != "42") $&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;&lt;span class="Apple-style-span"&gt;&lt;span class="Apple-style-span" style="background-color: #f3f3f3;"&gt; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span"&gt;&lt;span class="Apple-style-span" style="background-color: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;ask ("The favorite president?", _ == "Bush") $&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;&lt;span class="Apple-style-span"&gt;&lt;span class="Apple-style-span" style="background-color: #f3f3f3;"&gt;   &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span"&gt;&lt;span class="Apple-style-span" style="background-color: #f3f3f3;"&gt; &amp;nbsp;ask ("Is Java important?", _ == "") ;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;In &lt;i&gt;ask &lt;/i&gt;method we show user a question, wait for input, and decide whether we accept it, or if user want's to exit, it will. The above predicates mean: first value must be "42", second: president can't be "Bush", and third value must not be empty.&lt;br /&gt;&lt;br /&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;&lt;span class="Apple-style-span" style="background-color: #f3f3f3;"&gt; &lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span"&gt;&lt;span class="Apple-style-span" style="background-color: #f3f3f3;"&gt; &amp;nbsp;def ask(message: String, predicate: String =&amp;gt; Boolean) = {&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span"&gt;&lt;span class="Apple-style-span" style="background-color: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;&lt;span class="Apple-style-span"&gt;&lt;span class="Apple-style-span" style="background-color: #f3f3f3;"&gt; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span"&gt;&lt;span class="Apple-style-span" style="background-color: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;println (message)&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;&lt;span class="Apple-style-span"&gt;&lt;span class="Apple-style-span" style="background-color: #f3f3f3;"&gt; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span"&gt;&lt;span class="Apple-style-span" style="background-color: #f3f3f3;"&gt; &amp;nbsp; &amp;nbsp;val value = readLine&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;&lt;span class="Apple-style-span"&gt;&lt;span class="Apple-style-span" style="background-color: #f3f3f3;"&gt; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span"&gt;&lt;span class="Apple-style-span" style="background-color: #f3f3f3;"&gt; &amp;nbsp; &amp;nbsp;if(value == "quit") throw End&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;&lt;span class="Apple-style-span"&gt;&lt;span class="Apple-style-span" style="background-color: #f3f3f3;"&gt; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span"&gt;&lt;span class="Apple-style-span" style="background-color: #f3f3f3;"&gt; &amp;nbsp; &amp;nbsp;else if(predicate(value)) throw Again&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;&lt;span class="Apple-style-span"&gt;&lt;span class="Apple-style-span" style="background-color: #f3f3f3;"&gt; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span"&gt;&lt;span class="Apple-style-span" style="background-color: #f3f3f3;"&gt; &amp;nbsp; &amp;nbsp;else value&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;&lt;span class="Apple-style-span"&gt;&lt;span class="Apple-style-span" style="background-color: #f3f3f3;"&gt; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span"&gt;&lt;span class="Apple-style-span" style="background-color: #f3f3f3;"&gt; &amp;nbsp;}&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Ask method takes a message that is shown to user and a predicate which will test whether user's input was valid. Depending on the choice we construct the rest of the input list differently.&lt;br /&gt;&lt;br /&gt;The control flow interrupts are handled with exceptions. The user won't ever see those exceptions, though. It's all hidden under the cover. So how does the result be different when user has quitted? Here's how we inspect how the interaction went and get the values&lt;br /&gt;&lt;br /&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;&lt;span class="Apple-style-span"&gt;&lt;span class="Apple-style-span" style="background-color: #f3f3f3;"&gt; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span"&gt;&lt;span class="Apple-style-span" style="background-color: #f3f3f3;"&gt;&amp;nbsp;if(result success) {&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;&lt;span class="Apple-style-span"&gt;&lt;span class="Apple-style-span" style="background-color: #f3f3f3;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;&lt;span class="Apple-style-span"&gt;&lt;span class="Apple-style-span" style="background-color: #f3f3f3;"&gt; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span"&gt;&lt;span class="Apple-style-span" style="background-color: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;println (result !)&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;&lt;span class="Apple-style-span"&gt;&lt;span class="Apple-style-span" style="background-color: #f3f3f3;"&gt; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span"&gt;&lt;span class="Apple-style-span" style="background-color: #f3f3f3;"&gt;&amp;nbsp;} else {&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;&lt;span class="Apple-style-span"&gt;&lt;span class="Apple-style-span" style="background-color: #f3f3f3;"&gt; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span"&gt;&lt;span class="Apple-style-span" style="background-color: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;println ("quitted")&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;&lt;span class="Apple-style-span"&gt;&lt;span class="Apple-style-span" style="background-color: #f3f3f3;"&gt; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span"&gt;&lt;span class="Apple-style-span" style="background-color: #f3f3f3;"&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;We can ask from the result, whether it succeeded or not, and if it did, we can retrieve the result list with "!". For fail case, it would give empty list (we don't store partially constructed list, which we could).&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Let's see how this is achieved.&amp;nbsp;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="background-color: #cfe2f3;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span class="Apple-style-span"&gt;&lt;span class="Apple-style-span" style="background-color: #f3f3f3;"&gt;trait Builder[a] extends Function1[a, Builder[a]] {&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"&gt;&lt;span class="Apple-style-span" style="background-color: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;def get: List[a]&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"&gt;&lt;span class="Apple-style-span" style="background-color: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;def `!`: List[a] = get&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"&gt;&lt;span class="Apple-style-span" style="background-color: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;def `$`(x: =&amp;gt;a): Builder[a]&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"&gt;&lt;span class="Apple-style-span" style="background-color: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;def success: Boolean&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"&gt;&lt;span class="Apple-style-span" style="background-color: #f3f3f3;"&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&lt;/div&gt;&lt;div&gt;&lt;div&gt;We have trait for incremental building (Builder), which is a Function1. &amp;nbsp;One gives it a new value with apply or $ method and it will give back a new Builder with the given value applied to &amp;nbsp;it. Notice that the parameter is call-by-value, so it won't be evaluated immediately. The method ! is for retrieving the actual result.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"&gt;&lt;span class="Apple-style-span" style="background-color: #f3f3f3;"&gt;class EndBuilding[a] extends Builder[a] {&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"&gt;&lt;span class="Apple-style-span" style="background-color: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;&lt;span class="Apple-style-span"&gt;&lt;span class="Apple-style-span" style="background-color: #f3f3f3;"&gt; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span"&gt;&lt;span class="Apple-style-span" style="background-color: #f3f3f3;"&gt;def apply(x: a) = this&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"&gt;&lt;span class="Apple-style-span" style="background-color: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;&lt;span class="Apple-style-span"&gt;&lt;span class="Apple-style-span" style="background-color: #f3f3f3;"&gt; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span"&gt;&lt;span class="Apple-style-span" style="background-color: #f3f3f3;"&gt;override def get = List()&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"&gt;&lt;span class="Apple-style-span" style="background-color: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;&lt;span class="Apple-style-span"&gt;&lt;span class="Apple-style-span" style="background-color: #f3f3f3;"&gt; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span"&gt;&lt;span class="Apple-style-span" style="background-color: #f3f3f3;"&gt;def `$`(x: =&amp;gt;a): Builder[a] = this&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"&gt;&lt;span class="Apple-style-span" style="background-color: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;&lt;span class="Apple-style-span"&gt;&lt;span class="Apple-style-span" style="background-color: #f3f3f3;"&gt; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span"&gt;&lt;span class="Apple-style-span" style="background-color: #f3f3f3;"&gt;override def success = false&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"&gt;&lt;span class="Apple-style-span" style="background-color: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;}&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;We have two subclasses of Builder, one for building the list (ListBuilder) and one for termination (EndOfBuilding). The latter is simple: it doesn't do much, just return itself or tells that the construction failed (success = false).&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"&gt;&lt;span class="Apple-style-span" style="background-color: #f3f3f3;"&gt;class ListBuilder[a](init : List[a]) extends Builder[a] {&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;&lt;span class="Apple-style-span"&gt;&lt;span class="Apple-style-span" style="background-color: #f3f3f3;"&gt; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span"&gt;&lt;span class="Apple-style-span" style="background-color: #f3f3f3;"&gt;&amp;nbsp;override def success = true&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;&lt;span class="Apple-style-span"&gt;&lt;span class="Apple-style-span" style="background-color: #f3f3f3;"&gt; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span"&gt;&lt;span class="Apple-style-span" style="background-color: #f3f3f3;"&gt;&amp;nbsp;def apply(x: a): Builder[a] = new ListBuilder(x :: init)&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"&gt;&lt;span class="Apple-style-span" style="background-color: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;override def `$`(x: =&amp;gt;a): Builder[a] = {&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"&gt;&lt;span class="Apple-style-span" style="background-color: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;lazy val copy = x;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;&lt;span class="Apple-style-span"&gt;&lt;span class="Apple-style-span" style="background-color: #f3f3f3;"&gt;  &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span"&gt;&lt;span class="Apple-style-span" style="background-color: #f3f3f3;"&gt; &amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"&gt;&lt;span class="Apple-style-span" style="background-color: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;try {&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;&lt;span class="Apple-style-span"&gt;&lt;span class="Apple-style-span" style="background-color: #f3f3f3;"&gt;     &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span"&gt;&lt;span class="Apple-style-span" style="background-color: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;apply(x)&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;&lt;span class="Apple-style-span"&gt;&lt;span class="Apple-style-span" style="background-color: #f3f3f3;"&gt; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span"&gt;&lt;span class="Apple-style-span" style="background-color: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp; } catch {&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;&lt;span class="Apple-style-span"&gt;&lt;span class="Apple-style-span" style="background-color: #f3f3f3;"&gt; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span"&gt;&lt;span class="Apple-style-span" style="background-color: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp;case Again =&amp;gt; `$`(copy)&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;&lt;span class="Apple-style-span"&gt;&lt;span class="Apple-style-span" style="background-color: #f3f3f3;"&gt;  &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span"&gt;&lt;span class="Apple-style-span" style="background-color: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; case End =&amp;gt; new EndBuilding[a]&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;&lt;span class="Apple-style-span"&gt;&lt;span class="Apple-style-span" style="background-color: #f3f3f3;"&gt; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span"&gt;&lt;span class="Apple-style-span" style="background-color: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp; }&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;&lt;span class="Apple-style-span"&gt;&lt;span class="Apple-style-span" style="background-color: #f3f3f3;"&gt;   &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;&lt;span class="Apple-style-span"&gt;&lt;span class="Apple-style-span" style="background-color: #f3f3f3;"&gt; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span"&gt;&lt;span class="Apple-style-span" style="background-color: #f3f3f3;"&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;&lt;span class="Apple-style-span"&gt;&lt;span class="Apple-style-span" style="background-color: #f3f3f3;"&gt;  &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;&lt;span class="Apple-style-span"&gt;&lt;span class="Apple-style-span" style="background-color: #f3f3f3;"&gt;   &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span"&gt;&lt;span class="Apple-style-span" style="background-color: #f3f3f3;"&gt;override def get = init reverse&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;&lt;span class="Apple-style-span"&gt;&lt;span class="Apple-style-span" style="background-color: #f3f3f3;"&gt;  &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;&lt;span class="Apple-style-span"&gt;&lt;span class="Apple-style-span" style="background-color: #f3f3f3;"&gt;   &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span"&gt;&lt;span class="Apple-style-span" style="background-color: #f3f3f3;"&gt;def this(init: a) = this(List(init))&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;&lt;span class="Apple-style-span"&gt;&lt;span class="Apple-style-span" style="background-color: #f3f3f3;"&gt;   &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span"&gt;&lt;span class="Apple-style-span" style="background-color: #f3f3f3;"&gt;def this() = this(List())&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"&gt;&lt;span class="Apple-style-span" style="background-color: #f3f3f3;"&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;&lt;span class="Apple-style-span"&gt;&lt;span class="Apple-style-span" style="background-color: #f3f3f3;"&gt; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"&gt;&lt;span class="Apple-style-span" style="background-color: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;object End extends Throwable&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"&gt;&lt;span class="Apple-style-span" style="background-color: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;object Again extends Throwable&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;The ListBuilder is more interesting. $ method takes a call-by-name parameter x, essentially a thunk for later evaluation. We have a copy of it in lazy val for repeated use of x . After this we try to create a new ListBuilder with given value and at this point the x will be evaluated. This is important for the flow of the user interaction: at this point user is shown a message and input is waited to be given.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;If the evaluated thunk throws either Again, or End, we catch them and change the flow of the interaction from linear to a bit more complex, repetitive even. If the user says "quit", we get End object thrown, and decide that it's time to end the construction. So we give back EndBuilding object. This way the thunks later in the flow are not evaluated at all (because they are call-by-name and evaluation is not forced inside EndBuilding).&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;In case user says something that we have specifically constrained out of the valid values (in ask method), we want to evaluate the question again. Again object is thrown inside thunk and catched in $. Because we had a copy of the thunk in reserve, we can just call the $ method recursively, and get the same question/input again.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;In conclusion, I had a simple way to construct list, e.g. 5 $ 29 !; but it turned out to be a cool way to create a small interactive application. Whether this has any real user is up to you. Here is the whole program in one file:&amp;nbsp;&lt;a href="http://personal.inet.fi/koti/egaga/ohjelmointi/listcons.scala"&gt;http://personal.inet.fi/koti/egaga/ohjelmointi/listcons.scala&lt;/a&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Btw. I also noticed that the scaladoc distributed with 2.8 is quite unresponsive for filtering. So I made some dirty quick hacks and got it faster. Take a backup of your index.js in [scala]/bin/doc/scala-devel-docs/api/lib and put a copy of the following file there if you want to try it out:&amp;nbsp;&lt;a href="http://personal.inet.fi/koti/egaga/ohjelmointi/index.js"&gt;http://personal.inet.fi/koti/egaga/ohjelmointi/index.js&lt;/a&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Also, I've created a new blog that might interest you if you are a passionate programmer, and would like to hear my opinions about Factor, Haskell, Clojure, or programming in general.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;a href="http://huttuh.blogspot.com/"&gt;http://huttuh.blogspot.com/&lt;/a&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;If you still haven't had enough, see what references I recommended for programmers (articles, books, videos)&amp;nbsp;&lt;a href="http://personal.inet.fi/koti/egaga/recommendations/index.html"&gt;general&lt;/a&gt;&amp;nbsp;or &lt;a href="http://personal.inet.fi/koti/egaga/recommendations/misc.html"&gt;advanced/misc&lt;/a&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7480826096025842182-5156409097392859861?l=scalada.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://scalada.blogspot.com/feeds/5156409097392859861/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7480826096025842182&amp;postID=5156409097392859861' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7480826096025842182/posts/default/5156409097392859861'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7480826096025842182/posts/default/5156409097392859861'/><link rel='alternate' type='text/html' href='http://scalada.blogspot.com/2010/03/constructing-list-by-functionally.html' title='Constructing list by functionally threading state between user inputs'/><author><name>Henrik Huttunen</name><uri>http://www.blogger.com/profile/01845345214435219727</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://2.bp.blogspot.com/_0wWQ_NzU8Fs/S5adjK4NVpI/AAAAAAAAAB8/d6BDyZALfyo/S220/naama.JPG'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7480826096025842182.post-6734876225398370377</id><published>2008-04-13T20:27:00.009+03:00</published><updated>2010-03-03T08:47:35.727+02:00</updated><title type='text'>Named arguments</title><content type='html'>&lt;div&gt;edit at 3rd of March, 2010: Scala will have named arguments in 2.8. Great! &lt;a href="http://www.scala-lang.org/sid/1#"&gt;http://www.scala-lang.org/sid/1#&lt;/a&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;Scala unfortunately doesn't have named arguments. I would really like to have them, because they make code much clearer in some cases, and it's harder to make mistakes with them. That's why I'll show one way to simulate them.&lt;br /&gt;&lt;br /&gt;First, let's create the function that can handle homemade named arguments:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;    def f(x: {val name: String; val age: Int}) = {&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;f takes one argument, that contains the actual parameters we want. The type is shorthand for Any{ ... }.&lt;br /&gt;&lt;br /&gt;Next we have imported the contents of x to be visible inside method f. This is possible due to Scala's handling of objects as first class modules.&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;    import x._&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;And now we can use the attributes as if they were f's real parameters:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;    println(name + " is " + age + " years old")&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;How about from client's perspective? Well, client can just create a structural type that contains the needed attributes (actual arguments).&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;    f(new {val name = "Anthony"; val age = 5})&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;As you see, it's not really possible to make mistakes this way. But the calling has too much boilerplate, namely vals. So let's make it a bit better:&lt;br /&gt;&lt;br /&gt;We create a case class for each actual parameter.&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;    case class Name(name : String)&lt;br /&gt;   case class Age (age : Int)&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Now we can make very clear function signature:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;    def g(x: Name, y: Age) = {&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Unfortunately we have to import all parameters one by one.&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;    import x._, y._&lt;br /&gt;   println(name + " is " + age + " years old")&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;The client can call the method in the following way:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;    g(Name("Tim"), Age(2))&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;That's it. It's annoying that we have to create case classes, but it's tolerable in important cases.&lt;br /&gt;&lt;br /&gt;Here's the full code:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;object Test extends Application{&lt;br /&gt; def f(x: {val name: String; val age: Int}) = {&lt;br /&gt;   import x._&lt;br /&gt;   println(name + " is " + age + " years old")&lt;br /&gt; }&lt;br /&gt; f(new {val name = "Anthony"; val age = 5})&lt;br /&gt;&lt;br /&gt; case class Name(name : String)&lt;br /&gt; case class Age (age : Int)&lt;br /&gt;&lt;br /&gt; def g(x: Name, y: Age) = {&lt;br /&gt;   import x._, y._&lt;br /&gt;   println(name + " is " + age + " years old")&lt;br /&gt; }&lt;br /&gt; g(Name("Tim"), Age(2))&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Run the code and you get as output:&lt;br /&gt;Anthony is 5 years old&lt;br /&gt;Tim is 2 years old&lt;br /&gt;&lt;br /&gt;edit:&lt;br /&gt;&lt;br /&gt;On the client side, often one passes some constant values. If you call just like f(value1, value2, ... valueN), it's hard to know later when you see the code what the meaning for each value was; so you have to go see the API (if there's no tool help). Instead you have to define vals before the call:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;val age = 8&lt;br /&gt;val name = "Jim"&lt;br /&gt;f(age, name)&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;But now there's the issue that you have to write the variables twice, and it would be nice to see immeaditely on the call what the value was.&lt;br /&gt;&lt;br /&gt;Then:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;f(new {val age = 8; val name = "Jim"})&lt;/pre&gt; isn't that bad at all. Neither the case class equivalent. If you have many arguments to pass, calling with single argument per line looks nice:&lt;br /&gt;&lt;pre&gt;f(new { val age = 8&lt;br /&gt;       val name = "Jim"&lt;br /&gt;       val hobby = "blogging" })&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Named arguments are especially useful when constructing objects, because it's then when you have to pass lots of vaguely related arguments.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7480826096025842182-6734876225398370377?l=scalada.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://scalada.blogspot.com/feeds/6734876225398370377/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7480826096025842182&amp;postID=6734876225398370377' title='5 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7480826096025842182/posts/default/6734876225398370377'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7480826096025842182/posts/default/6734876225398370377'/><link rel='alternate' type='text/html' href='http://scalada.blogspot.com/2008/04/named-arguments.html' title='Named arguments'/><author><name>Henrik Huttunen</name><uri>http://www.blogger.com/profile/01845345214435219727</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://2.bp.blogspot.com/_0wWQ_NzU8Fs/S5adjK4NVpI/AAAAAAAAAB8/d6BDyZALfyo/S220/naama.JPG'/></author><thr:total>5</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7480826096025842182.post-3005842285394254695</id><published>2008-04-09T19:45:00.005+03:00</published><updated>2008-04-10T13:16:28.847+03:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='quote'/><category scheme='http://www.blogger.com/atom/ns#' term='implicits'/><category scheme='http://www.blogger.com/atom/ns#' term='scala'/><title type='text'>On defence of implicit arguments and the lack of type inference power</title><content type='html'>I found two quite recent comments by Martin Odersky (main developer of Scala) that give insight to two commonly arised questions. They are 1) why implicit arguments exists, and aren't they too dangerous? And 2) Why on earth is this so cool type inference system behaving like an idiot, and isn't inferring some obvious cases.&lt;br /&gt;&lt;br /&gt;Here are the quotes and links to the original source.&lt;br /&gt;&lt;br /&gt;1)&lt;br /&gt;&lt;br /&gt;"In practice, of course, you want to find the right mixture between expressiveness and safety. -- -- and you'll accept some implicit parameters at places where they are really useful. And they are amazingly useful when used as a tool in the right hands. &lt;br /&gt;&lt;br /&gt;For instance ScalaCheck lets you write properties of your programs and then constructs unit tests for these properties automatically. Several bugs in the standard Scala library have been found this way. Without implicit parameters, the plumbing you'd have to do to set up the properties would make them much uglier, so people most likely would not write any. So that's an example where implicits are really useful. Expect to see many more libraries that do amazing things like ScalaCheck in the future.&lt;br /&gt;&lt;br /&gt;-- -- &lt;br /&gt;&lt;br /&gt;P.S. I think this discussion highlights a bit the design philosophies behind Java and Scala. They are not the same. Scala puts more trust in its users that they will do the right thing. Maybe this assumption is wrong, and users will make a mess of it, but that's what Scala is."&lt;br /&gt;&lt;br /&gt;Martin Odersky, posted on March 9, 2008 at 6:16 am&lt;br /&gt;&lt;br /&gt;&lt;a href="http://www.artima.com/forums/flat.jsp?forum=276&amp;thread=226525&amp;start=0&amp;msRange=15"&gt;Original post&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;2)&lt;br /&gt;&lt;br /&gt;"The reason Scala does not have Hindley/Milner type inference is that it is very difficult to combine with features such as overloading (the ad-hoc variant, not type classes), record selection, and subtyping. I’m not saying impossible — there exist a number of extensions that incorporate these features; in fact I have been guitly of some of them myself. I’m just saying it’s very difficult to make this work well in practice, where one needs to have small type expressions, and good error messages. It’s not a shut case either — many researchers are working on pushing the boundaries here (look for instance at Remy’s MLF). But right now it is a tradeoff of better type inferencing vs better support for these features. You can make the tradeoff both ways. The fact that we wanted to integrate with Java tipped the scales in favor of subtyping and away from Hindley/Milner."&lt;br /&gt;&lt;br /&gt;Martin Odersky, posted on April 9, 2008 at 2:08 am&lt;br /&gt;&lt;br /&gt;&lt;a href="http://www.codecommit.com/blog/scala/universal-type-inference-is-a-bad-thing"&gt;Original post&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;I hope this is not violation of any copyright ;)&lt;br /&gt;&lt;br /&gt;Another news regarding Scala are that the contractiviness requirement for implicits was removed by David MacIver's suggestion. Moreover in one month Scala is likely to have some kind of version of virtual classes, so it's possible to extend class hierarchies in one more powerful way. I hope there will be a good documentation available when it's out *cough* existential types *cough*. :)&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7480826096025842182-3005842285394254695?l=scalada.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://scalada.blogspot.com/feeds/3005842285394254695/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7480826096025842182&amp;postID=3005842285394254695' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7480826096025842182/posts/default/3005842285394254695'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7480826096025842182/posts/default/3005842285394254695'/><link rel='alternate' type='text/html' href='http://scalada.blogspot.com/2008/04/on-defence-of-implicit-arguments-and.html' title='On defence of implicit arguments and the lack of type inference power'/><author><name>Henrik Huttunen</name><uri>http://www.blogger.com/profile/01845345214435219727</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://2.bp.blogspot.com/_0wWQ_NzU8Fs/S5adjK4NVpI/AAAAAAAAAB8/d6BDyZALfyo/S220/naama.JPG'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7480826096025842182.post-6659822587648976697</id><published>2008-03-17T16:55:00.008+02:00</published><updated>2008-03-17T17:18:52.737+02:00</updated><title type='text'>WhenDone - a todo application</title><content type='html'>I have now published my first open source Scala application, WhenDone. It's a todo application primarily for a single user. Goals are that it's easy to add a task, and easy to find a task do to. It's in its early phase, but is usable. I mainly develop this for my own needs, but it's a general app, so others might find it useful too. The most interesting thing might be that it is command based, even though it uses Swing! How perverted is that :).&lt;br /&gt;&lt;br /&gt;Here's two screen captures from an example session: &lt;br /&gt;&lt;a href="http://whendone.googlecode.com/files/examplesession1.png"&gt; Example session, part 1&lt;/a&gt;&lt;br /&gt;&lt;a href="http://whendone.googlecode.com/files/examplesession2.png"&gt; Example session, part 2&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;WhenDone is under the MIT lisence. More information and downloadable content can be found at Google Code: &lt;a href="http://code.google.com/p/whendone/"&gt; WhenDone's project page&lt;/a&gt;.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7480826096025842182-6659822587648976697?l=scalada.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://scalada.blogspot.com/feeds/6659822587648976697/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7480826096025842182&amp;postID=6659822587648976697' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7480826096025842182/posts/default/6659822587648976697'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7480826096025842182/posts/default/6659822587648976697'/><link rel='alternate' type='text/html' href='http://scalada.blogspot.com/2008/03/whendone-todo-application.html' title='WhenDone - a todo application'/><author><name>Henrik Huttunen</name><uri>http://www.blogger.com/profile/01845345214435219727</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://2.bp.blogspot.com/_0wWQ_NzU8Fs/S5adjK4NVpI/AAAAAAAAAB8/d6BDyZALfyo/S220/naama.JPG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7480826096025842182.post-6828568749669987198</id><published>2008-03-16T21:43:00.006+02:00</published><updated>2008-04-19T11:25:00.276+03:00</updated><title type='text'>Implicit conversions - magical and demonic</title><content type='html'>Implicit conversion is a useful mechanism, because it lets you extend libraries retroactively, without actually changing them. Let's take a common example.&lt;br /&gt;&lt;br /&gt;We would like to repeat some String, say "nice" three times. We could write it as:&lt;br /&gt;&lt;pre&gt;def *(times: Int, original: String) = {&lt;br /&gt;def multiply(times: Int): String = {&lt;br /&gt; if(times &gt; 1) original + multiply(times - 1)&lt;br /&gt; else original&lt;br /&gt;}&lt;br /&gt;multiply(times)&lt;br /&gt;}&lt;/pre&gt;&lt;br /&gt;As a bit of a sidenote, multiply is not tail-recursive, because its recursive call is not the last thing it does. So it will blow up the stack space. Here's how we can make it tail recursive:&lt;br /&gt;&lt;pre&gt;def *(times: Int, original: String) = {&lt;br /&gt;def multiply(times: Int, accumulated: String): String = {&lt;br /&gt; if(times &gt; 1) multiply(times - 1, accumulated + original)&lt;br /&gt; else original + accumulated&lt;br /&gt;}&lt;br /&gt;multiply(times, "")&lt;br /&gt;}&lt;/pre&gt;&lt;br /&gt;This technique is called accumulation. We use additional parameter 'accumulated' to pile up the result incrementally. Now the compiler can optimize the recursive calls, and stack won't grow every call.&lt;br /&gt;&lt;br /&gt;With '*' method defined in some object, and imported in use-site, we could now multiply strings with *("nice", 3). However, it's not as nice as we would like it to be, e.g. "nice" * 3. But how can we get there, because obviously we can't go and put the '*' method to String class. Well, the first thing to do is to create a class StringRepeated that has that method.&lt;br /&gt;&lt;pre&gt;class StringRepeated(original: String){&lt;br /&gt;def *(times: Int) = {&lt;br /&gt; def multiply(times: Int, accumulated: String): String = {&lt;br /&gt;   if(times &gt; 1) multiply(times - 1, accumulated + original)&lt;br /&gt;   else original + accumulated&lt;br /&gt; }&lt;br /&gt; multiply(times, "")&lt;br /&gt;}&lt;br /&gt;}&lt;/pre&gt;&lt;br /&gt;Now if we create a StringRepeated, we can use the '*' like this:&lt;br /&gt;&lt;pre&gt;val repeated = (new StringRepeated("nice")) * 3&lt;br /&gt;// == "nicenicenice"&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;But we can't do this on normal Strings directly. The implicit conversion is what comes to rescue; it makes the conversion from String to StringRepeated.&lt;br /&gt;&lt;br /&gt;implicit def string2repeated(x: String) = new StringRepeated(x)&lt;br /&gt;&lt;br /&gt;That's it. Now when compiler sees a "nice" * 3, it first concludes that there is no '*' method defined in String. Then it looks for implicit conversion that would give a new object that has a '*' with correct parameter type. If there is no ambiguouty in choosing what implicit conversion to apply, the compiler will insert the conversion.&lt;br /&gt;&lt;br /&gt;So "nice" * 3 will be statically translated to something like (new StringRepeated("nice")) * 3.&lt;br /&gt;&lt;br /&gt;Now as this small example shows, implicit conversion can be somewhat handy. For additional example, I have an application that prints text that is partly colorized or otherwise styled. I have taken advantage of implicit conversion so that I can write printWith("Hi," | "this" * Bold | " is " * Fore(RED) | "cool."). It will print sequentially "Hi, &lt;b&gt;this&lt;/b&gt;&lt;span style="color:#cc0000;"&gt; is&lt;/span&gt; cool."&lt;br /&gt;&lt;br /&gt;Now I like this feature, but I think it's a bit dangerous. It's not always easy to see what conversions are happening, because they are automatically inserted. Good news is that you can control their use scope by importing the implicit conversions only to places where you really want them. Next I give you an example that combined with another unfortunate feature makes my head steam.&lt;br /&gt;&lt;br /&gt;In Scala == is structural equality test method, unlike in Java, where it is reference equality test. It takes one argument type of Any, which means you can compare your object against any object. I mean any, and compiler will allow you that. Doesn't sound too bad, you say? Well, if you have lots of inheritance, you might really want that ability, so that you can reveal whether two objects are the same even if their static type is not the same. But usually I just want to know two statically equivalently typed objects to be tested against each other, not arbitrary objects.&lt;br /&gt;&lt;br /&gt;I have had problems with this simply, because you don't always compare things you should. Humans do mistakes (I sometimes wonder, am I ever doing something *right*). For example, I might have a tuple of Ints, which has name 'boom'. And i have another tuple 'doom', and I'd like to compare their first elements, i.e. boom._1 == doom._1. But I might be a bit sleepy, and write "boom == doom._1", i.e. comparing a tuple against an Int. Compiler won't say that you are comparing completely different objects. It just sings logically incorrect bytecode. It might be very hard to notice that the comparison isn't ever going to give a true value just by testing it few times.&lt;br /&gt;&lt;br /&gt;Ok, that's bad enough as it is, but when we mix implicit conversions with this magical soup, we are really doomed. An example: String has no reverse method. Therefore it has been extended with RichString in the same kind of way I described earlier for RepeatedString. When you say "yay" reverse, you get a RichString, not String. Guess what, "yay".reverse == "yay" won't give you true. Happy debugging times ahead, my friend. It isn't helping that with type inference in use, even with intermediate variables (val x = "yay" reverse) you might think you're dealing with a normal String. That might happen if you just forgot that there ever was a RichString class, and thought that reverse was defined in String.&lt;br /&gt;&lt;br /&gt;My conclusion (temporary, as they always are) is that when you need concise syntax for some operations, give a thought about implicit conversions. But be sure to think carefully how it interacts with other types, and especially if you are dealing with multiple conversions.&lt;br /&gt;&lt;br /&gt;True wizards use their magic sparingly.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7480826096025842182-6828568749669987198?l=scalada.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://scalada.blogspot.com/feeds/6828568749669987198/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7480826096025842182&amp;postID=6828568749669987198' title='3 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7480826096025842182/posts/default/6828568749669987198'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7480826096025842182/posts/default/6828568749669987198'/><link rel='alternate' type='text/html' href='http://scalada.blogspot.com/2008/03/implicit-conversions-magical-and.html' title='Implicit conversions - magical and demonic'/><author><name>Henrik Huttunen</name><uri>http://www.blogger.com/profile/01845345214435219727</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://2.bp.blogspot.com/_0wWQ_NzU8Fs/S5adjK4NVpI/AAAAAAAAAB8/d6BDyZALfyo/S220/naama.JPG'/></author><thr:total>3</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7480826096025842182.post-6988018535095735003</id><published>2008-02-05T23:54:00.000+02:00</published><updated>2008-02-06T00:21:54.114+02:00</updated><title type='text'>Importing all classes but explicitly excluded</title><content type='html'>Importing is more powerful in Scala than in Java, because it's possible to use import inside functions i.e. you can locally bind the libraries you need. But there's also some syntactic sugar, f.ex. you can import more than one class from one path:&lt;br /&gt;&lt;pre&gt;  object Top{&lt;br /&gt;    object A&lt;br /&gt;    class B&lt;br /&gt;    trait C&lt;br /&gt;  }&lt;br /&gt;&lt;/pre&gt;&lt;pre&gt;  import Top.{A, C} // imports A and C from Top package&lt;/pre&gt;It's possible to import all in one go with underscore '_'.&lt;br /&gt;&lt;pre&gt;  import Top._ // imports A, B, C&lt;/pre&gt;What if we have a clash of names, e.g. 'A' is used in two paths.&lt;br /&gt;&lt;pre&gt;  object Top2{ object A }&lt;/pre&gt;We can import and rename the other one (the new name is alias for the long name in that scope):&lt;br /&gt;&lt;pre&gt;  import Top.A&lt;br /&gt;  import Top2.{A =&gt; OtherA}&lt;br /&gt;&lt;/pre&gt;What if we need to import all but, say two classes. We could have lots of classes  to explicitly type if we do it importing class by class; just using underscore would import also unwanted classes so it is not an option.&lt;br /&gt;&lt;br /&gt;We can rename the unwanted to _, which in practice means that the naming is ignored, so effectively it's not imported at all. Let's pretend we have lots of classes in Top1, and we don't need just B and C.&lt;br /&gt;&lt;pre&gt;  import Top.{B =&gt; _, C =&gt; _, _}&lt;/pre&gt;The last '_' tells to compiler to import all the others.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7480826096025842182-6988018535095735003?l=scalada.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://scalada.blogspot.com/feeds/6988018535095735003/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7480826096025842182&amp;postID=6988018535095735003' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7480826096025842182/posts/default/6988018535095735003'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7480826096025842182/posts/default/6988018535095735003'/><link rel='alternate' type='text/html' href='http://scalada.blogspot.com/2008/02/importing-all-classes-but-explicitly.html' title='Importing all classes but explicitly excluded'/><author><name>Henrik Huttunen</name><uri>http://www.blogger.com/profile/01845345214435219727</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://2.bp.blogspot.com/_0wWQ_NzU8Fs/S5adjK4NVpI/AAAAAAAAAB8/d6BDyZALfyo/S220/naama.JPG'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7480826096025842182.post-241658037532588320</id><published>2008-02-03T19:58:00.000+02:00</published><updated>2008-02-04T17:54:16.178+02:00</updated><title type='text'>this.type for chaining method calls</title><content type='html'>Scala has powerful mechanisms borrowed from other languages, but often one small unique feature is not discussed: &lt;span style="font-weight: bold;"&gt;this.type&lt;/span&gt;. In this article I'll explain it shortly and show you a demonstration.&lt;br /&gt;&lt;br /&gt;this.type is a singleton type, which means the type represents a certain object, not class of objects. It helps to solve the problem when you need to chain method calls of a class hierarchy, i.e. "value.method1.method2", where method1 is in super class A and method2 is in deriving class B.&lt;br /&gt;&lt;pre&gt;  class A {def method1: A = this }&lt;br /&gt;  class B extends A (def method2: B = this}&lt;br /&gt;  val b = new B&lt;br /&gt;&lt;/pre&gt;Now we have defined the hierarchy, and created an instance of B named 'b'. Let's see about the chaining of method calls: The following works fine, because method2 returns type B which has method1:&lt;br /&gt;&lt;pre&gt;  b.method2.method1&lt;/pre&gt;However, this won't &lt;pre&gt;  b.method1.method2&lt;/pre&gt; because method1's result type is A, and so compiler thinks that the object hasn't got the method2.&lt;br /&gt;&lt;br /&gt;We could solve this by overriding the method1 in B, which calls the super classes' method1 to do whatever work it does. The result type is covariantly set as B: &lt;pre&gt;  class B extends A{&lt;br /&gt;    override def method1: B = {super.method1; this };&lt;br /&gt;    ...&lt;br /&gt;  }&lt;/pre&gt; But this is extra work for every subclass of A that needs method chaining!&lt;br /&gt;&lt;br /&gt;Here's the other way we can do it in Scala: Using this.type we can tell compiler that the resulting object from method1 is exactly the same as b, so compiler can infer that 'yeah, the resulting object from method1 has method2 too'.&lt;br /&gt;&lt;pre&gt;  class A { def method1: this.type = this }&lt;br /&gt;  class B extends A { def method2: this.type = this }&lt;br /&gt;  // in method2 this.type is not a necessity&lt;br /&gt;  // unless there's subclass of B.&lt;/pre&gt;Now&lt;br /&gt;&lt;pre&gt;  val b = new B&lt;br /&gt;  b.method1.method2&lt;/pre&gt;works with both alternatives.&lt;br /&gt;&lt;br /&gt;For more specific information you can see: &lt;a href="http://lamp.epfl.ch/%7Eodersky/papers/ScalableComponent.pdf"&gt;Scalable Component Abstractions&lt;/a&gt; which is a very good read otherwise, too.&lt;br /&gt;&lt;br /&gt;Scala has also linear mixin composition of which you can read also on the same link. I'm not going into details, but idea is to have partial implementations as traits which we mixin together. We use them in this article, because we want to create a library, but we are not sure how we'd like to extend it later and want to take only the parts we need. Additionally we want the chaining work with all the upcoming traits uniformly, not just with the methods in the superclass. This is achieved with traits and this.type.&lt;br /&gt;&lt;br /&gt;The heart is CommandCenter, which queues up given computations, which are just normal Scala functions, of type Unit =&gt; Any.&lt;pre&gt;  trait CommandCenter{&lt;br /&gt;    protected var queue = List[Unit =&gt; Any]()&lt;br /&gt;    def &lt;+(computation: =&gt; Any): this.type = {&lt;br /&gt;      queue :::= List[Unit=&gt;Any]({x =&gt; computation})&lt;br /&gt;      this&lt;br /&gt;    }&lt;br /&gt;  }&lt;/pre&gt;Now we can make objects of CommandCenter that can chain adding of computations, e.g. &lt;pre&gt;  val cmd = new CommandCenter{}&lt;br /&gt;  cmd &lt;+ Console.println("hi") &lt;+ {network.send("bye")}&lt;/pre&gt; Certainly we'd like to execute those computations later, but we don't want to pollute the same trait, because it's different responsibility. Here's first a helper class, which just forces the evalution of computations that are in the list.&lt;br /&gt;&lt;pre&gt;  def executeAll(list: List[Unit =&gt; Any]) &lt;br /&gt;  = list foreach {_()}&lt;/pre&gt; Here's the trait for actual execution:&lt;br /&gt;&lt;pre&gt;  trait ExecuteCommands extends CommandCenter{&lt;br /&gt;    def execute: Unit = executeAll(queue)&lt;br /&gt;  }&lt;/pre&gt; Now we'd like to extend this thing so that we can make a group of computations and give them names by which we can later ask them to be evaluated.&lt;br /&gt;&lt;pre&gt;  trait GroupedCommands extends CommandCenter {&lt;br /&gt;    import scala.collection.mutable.HashMap&lt;br /&gt;    protected val groups = HashMap[String, List[Unit=&gt;Any]]()&lt;br /&gt;    def &gt;&gt;(name: String) = {&lt;br /&gt;      groups += ((name, queue))&lt;br /&gt;     queue = List()&lt;br /&gt;    }&lt;br /&gt;  }&lt;/pre&gt;'&gt;&gt;' method ends the construction of computations; it takes all the computations in the queue and names it as a group, and clears the original queue so that new computations can be binded together.&lt;br /&gt;&lt;br /&gt;We have also different trait for execution group computations, but we skip that (you can see it in the complete source code).&lt;br /&gt;&lt;br /&gt;Now we can create a test case. First we have a construct method that only creates the computations. We restrict ourself from knowing more than grouping build operations i.e. GroupedCommands trait. &lt;pre&gt;  def construct(command: GroupedCommands) = {&lt;br /&gt;    var (x, y) = (1.0, 1.0)&lt;br /&gt;    def printx = Console.println("x: " + x)&lt;br /&gt;    command &lt;+ printx &lt;+ { x *= 2 } &lt;+ printx &gt;&gt; "doubleX"&lt;br /&gt;    command &lt;+ printx &lt;+ { x /= 2 } &lt;+ printx &gt;&gt; "halfX"&lt;br /&gt;  } &lt;/pre&gt; Of course &lt;+ is kinda useless, we could just make a one big computation with {comp1; comp2; ... compN}, but this is only an example, though by partioning them to be differentiable, one could use for example time delay between evaluations.  Here's the execute part: &lt;br /&gt;&lt;pre&gt;  def execute(command: GroupExecution) = {&lt;br /&gt;    command execute("doubleX")&lt;br /&gt;    command execute("doubleX")&lt;br /&gt;    command execute("halfX")&lt;br /&gt;  }&lt;/pre&gt; And finally the test that gives observable results: &lt;br /&gt;&lt;pre&gt;  val command = new CommandCenter &lt;br /&gt;                with GroupedCommands with GroupExecution&lt;br /&gt;  construct(command)&lt;br /&gt;  execute(command)&lt;br /&gt;&lt;/pre&gt;It prints: &lt;pre&gt;  x: 1.0, x: 2.0, x: 2.0, 4.0, x: 4.0, x: 2.0&lt;/pre&gt;Here's the complete &lt;a href="http://users.utu.fi/hvkhut/scalada/thistype.scala"&gt;source code&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;So now you know of this.type. Spread the word, for rarely anyone mentions it.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7480826096025842182-241658037532588320?l=scalada.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://scalada.blogspot.com/feeds/241658037532588320/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7480826096025842182&amp;postID=241658037532588320' title='5 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7480826096025842182/posts/default/241658037532588320'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7480826096025842182/posts/default/241658037532588320'/><link rel='alternate' type='text/html' href='http://scalada.blogspot.com/2008/02/thistype-for-chaining-method-calls.html' title='this.type for chaining method calls'/><author><name>Henrik Huttunen</name><uri>http://www.blogger.com/profile/01845345214435219727</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://2.bp.blogspot.com/_0wWQ_NzU8Fs/S5adjK4NVpI/AAAAAAAAAB8/d6BDyZALfyo/S220/naama.JPG'/></author><thr:total>5</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7480826096025842182.post-55591058606899821</id><published>2008-01-28T18:44:00.000+02:00</published><updated>2008-01-31T14:57:25.415+02:00</updated><title type='text'>Existential types</title><content type='html'>Java generics haven't been fully supported in Scala until now. They're not in the newest official release, but you can already use them checking out them from the SVN or downloading a nightly build. To get Java generic interoperatibility working, Scala has gotten a new feature, existential types.&lt;br /&gt;&lt;br /&gt;Existential types are in form of &lt;span style="font-weight: bold;"&gt;T forSome {type Q}&lt;/span&gt;, where Q part contains type declarations. In practice we want to just say some restrictions for T.&lt;br /&gt;&lt;br /&gt;E.g. &lt;span style="font-weight: bold;"&gt;def m(x : t &lt;/span&gt;&lt;span style="font-weight: bold;"&gt;forSome  {type t &lt;: A}&lt;/span&gt;&lt;span style="font-weight: bold;"&gt;) = x&lt;/span&gt; is a method that takes arguments that conform to t &lt;: A.  You can read more specific info from the &lt;a href="http://www.scala-lang.org/docu/files/ScalaReference.pdf"&gt;Scala specification&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;One interesting thing about existentials is that you can use them to use-site variance when it's not possible to make the type covariant. Let's see what that means.&lt;br /&gt;&lt;ul&gt;&lt;li&gt;class Couple[a](val first: a, val second: a)&lt;/li&gt;&lt;li&gt;trait Creature&lt;/li&gt;&lt;li&gt;trait Human extends Creature&lt;/li&gt;&lt;/ul&gt;So we have a Couple class which has one type parameter, but two arguments of the same type. We also have some kind of hierarchy of traits which we use as type arguments to make a couple of type Couple[Human]:&lt;br /&gt;&lt;ul&gt;&lt;li&gt;val couple = new Couple(new Human{}, new Human{})&lt;br /&gt;&lt;/li&gt;&lt;/ul&gt;Now, without changes to Couple, we cannot pass &lt;span style="font-style: italic;"&gt;couple &lt;/span&gt;to a function, which takes Couple[Creature] as argument, because Couple is invariant. I.e. &lt;span style="font-weight: bold;"&gt;S = T iff Couple[S] = Couple[T]&lt;/span&gt; holds.  We need covariance to achieve that. I.e. &lt;span style="font-weight: bold;"&gt;S &lt;= T iff Couple[S] &lt;= Couple[T]&lt;/span&gt;. We could make Couple covariant in definition site by:&lt;br /&gt;&lt;ul&gt;&lt;li&gt;class Couple[+a](...)&lt;/li&gt;&lt;/ul&gt;... and then we could pass &lt;span style="font-style: italic;"&gt;couple &lt;/span&gt;to a function like:&lt;br /&gt;&lt;ul&gt;&lt;li&gt;def haveFun1(c: Couple[Creature]) = c&lt;/li&gt;&lt;li&gt;haveFun1(couple) // compiles only if Couple is covariant in its type parameter&lt;br /&gt;&lt;/li&gt;&lt;/ul&gt;But we can do this without making changes to Couple definition, which could be impossible in some cases, or just not preferable. With the following definition we get what we want:&lt;br /&gt;&lt;ul&gt;&lt;li&gt;def haveFun2(c: Couple[x] forSome {type x &lt;: Creature}) = c&lt;/li&gt;&lt;li&gt;haveFun2(couple) // compiles&lt;br /&gt;&lt;/li&gt;&lt;/ul&gt;There's a nicer syntax alternative (haveFun2 == haveFun3):&lt;br /&gt;&lt;ul&gt;&lt;li&gt;def haveFun3(c: Couple[_ &lt;: Creature]) = c&lt;/li&gt;&lt;/ul&gt;This shows how existentials allow the treatment of a Human Couple as a Creature Couple in the client code.&lt;br /&gt;&lt;br /&gt;If you want to read more about the usefulness of existentials, see Burak Emir's interesting article how they relate to pattern matching &lt;a href="http://lamp.epfl.ch/%7Eemir/bqbase/2007/06/13/existentials.html"&gt;here&lt;/a&gt;.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7480826096025842182-55591058606899821?l=scalada.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://scalada.blogspot.com/feeds/55591058606899821/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7480826096025842182&amp;postID=55591058606899821' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7480826096025842182/posts/default/55591058606899821'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7480826096025842182/posts/default/55591058606899821'/><link rel='alternate' type='text/html' href='http://scalada.blogspot.com/2008/01/existential-types.html' title='Existential types'/><author><name>Henrik Huttunen</name><uri>http://www.blogger.com/profile/01845345214435219727</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://2.bp.blogspot.com/_0wWQ_NzU8Fs/S5adjK4NVpI/AAAAAAAAAB8/d6BDyZALfyo/S220/naama.JPG'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7480826096025842182.post-8568432906147484415</id><published>2008-01-27T22:44:00.000+02:00</published><updated>2008-01-27T23:07:31.265+02:00</updated><title type='text'>About the blog</title><content type='html'>Scalada is a blog about programming in Scala language. It combines functional and object-oriented programming paradigms pretty neatly, and gives powerful abstractions based on theoretical background.&lt;br /&gt;&lt;br /&gt;See official &lt;a href="http://www.scala-lang.org/"&gt;Scala website&lt;/a&gt;. I've written some examples about Scala before, you can find them currently &lt;a href="http://users.utu.fi/hvkhut/scalad/scalad.htm"&gt;here&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;The posts won't be necessarily long, just quick observations about things I encounter on the Scala mailing list, or when programming. I hope this blog will be helpful to beginners and to people who don't actively follow mailing list posts.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7480826096025842182-8568432906147484415?l=scalada.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://scalada.blogspot.com/feeds/8568432906147484415/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7480826096025842182&amp;postID=8568432906147484415' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7480826096025842182/posts/default/8568432906147484415'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7480826096025842182/posts/default/8568432906147484415'/><link rel='alternate' type='text/html' href='http://scalada.blogspot.com/2008/01/about-blog.html' title='About the blog'/><author><name>Henrik Huttunen</name><uri>http://www.blogger.com/profile/01845345214435219727</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://2.bp.blogspot.com/_0wWQ_NzU8Fs/S5adjK4NVpI/AAAAAAAAAB8/d6BDyZALfyo/S220/naama.JPG'/></author><thr:total>2</thr:total></entry></feed>
