<?xml version="1.0" encoding="utf-8" standalone="yes" ?>
<feed xmlns="http://www.w3.org/2005/Atom">

	<title>Planet Scala</title>
	<link rel="self" href="http://www.drmaciver.com/planetscala/atom.xml"/>
	<link href="http://www.drmaciver.com/planetscala/"/>
	<id>http://www.drmaciver.com/planetscala/atom.xml</id>
	<updated>2008-12-03T22:42:04+00:00</updated>
	<generator uri="http://www.planetplanet.org/">Planet/2.0 +http://www.planetplanet.org</generator>

	<entry>
		<title type="html">Manifests: Reified Types</title>
		<link href="http://scala-blogs.org/2008/10/manifests-reified-types.html"/>
		<id>tag:blogger.com,1999:blog-6374583985636407395.post-6065577597713247493</id>
		<updated>2008-12-03T08:37:00+00:00</updated>
		<content type="html">&lt;span&gt;&lt;blockquote&gt;&lt;span&gt;Reification&lt;/span&gt; (n.): When an abstract concept [...] is treated as a concrete 'thing'.&lt;sup&gt;&lt;a href=&quot;http://en.wikipedia.org/wiki/Reification_%28Marxism%29&quot;&gt;[1]&lt;/a&gt;&lt;/sup&gt;&lt;/blockquote&gt;&lt;/span&gt;When Java-the-language added generic types in version 1.5, Java-the-virtual-machine (JVM) did not. Generic types are a fiction of the compiler. They exist at compile time, but they are omitted from the generated bytecode and are therefore unavailable at run time. This phenomenon is known as &lt;span&gt;erasure&lt;/span&gt;.&lt;br /&gt;&lt;br /&gt;By contrast, when C# added generic types in version 2.0, the .NET Common Language Runtime (CLR) added them as well. This allows C# to access information about generic types at run time. We say that C#'s generic types are &lt;span&gt;reified&lt;/span&gt;.&lt;br /&gt;&lt;br /&gt;Java's type erasure leads to some peculiar limitations. To deal with these limitations, Java programmers often find themselves passing around java.lang.Class&amp;lt;T&amp;gt; objects: concrete manifestations of the otherwise abstract concept that is the type &quot;T&quot;.&lt;br /&gt;&lt;br /&gt;Starting with version 2.7.2, Scala has added &lt;span&gt;manifests&lt;/span&gt;, an undocumented (and still experimental) feature for reifying types. They take advantage of a pre-existing Scala feature: &lt;span&gt;implicit parameters&lt;/span&gt;.&lt;br /&gt;&lt;br /&gt;To use Manifests, simply add an implicit &lt;code&gt;scala.reflect.Manifest[T]&lt;/code&gt; parameter to your method, like so:&lt;br /&gt;&lt;blockquote&gt;&lt;pre&gt;&lt;code&gt;def name[T](implicit m: scala.reflect.Manifest[T]) = m.toString&lt;/code&gt;&lt;/pre&gt;&lt;/blockquote&gt;This method prints the name of any Scala type. To use it, invoke the method with some type parameter:&lt;br /&gt;&lt;blockquote&gt;&lt;pre&gt;&lt;code&gt;name[Int =&gt; Int]&lt;br /&gt;// returns &quot;scala.Function1[int, int]&quot;&lt;/code&gt;&lt;/pre&gt;&lt;/blockquote&gt;When using implicit parameters, you usually have to declare a implicit identifier with the same type as your method expects, in the same scope where the method is called. With Manifests, the compiler automatically injects the implicit parameter for you, as long as it has enough type information to generate a Manifest. Essentially, this is a way of carrying over type information available at compile time into objects available at run time.&lt;br /&gt;&lt;br /&gt;&lt;span&gt;An Example: Generic Collections Optimized for Primitives&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;In Java, generic collections can't be used with primitive types. The &lt;a href=&quot;http://java.sun.com/j2se/1.5.0/docs/guide/language/autoboxing.html&quot;&gt;boxed types&lt;/a&gt; must be used instead. This has implications for both run time performance and memory consumption. Despite HotSpot's best optimization efforts, boxed types can add significant overhead in performance-critical code.&lt;br /&gt;&lt;br /&gt;In C#, by contrast, generic collections are optimized for performance with primitive types. This is possible because C#'s types are reified. If your code calls for a List&amp;lt;T&amp;gt;, C# knows at run time what T is and can use the specific implementation of List that is optimized for your T.&lt;br /&gt;&lt;br /&gt;Let's see what Scala can do with Manifests and a lot of help from the &lt;a href=&quot;http://fastutil.dsi.unimi.it/&quot;&gt;fastutil library&lt;/a&gt;, which provides 1000+ (!) Java collection classes optimized for primitives.&lt;br /&gt;&lt;blockquote&gt;&lt;pre&gt;&lt;code&gt;import scala.reflect.Manifest&lt;br /&gt;import it.unimi.dsi.fastutil._&lt;br /&gt;&lt;br /&gt;def mkList[T](implicit m: Manifest[T]) = {&lt;br /&gt;  (m.toString match {&lt;br /&gt;    case &quot;boolean&quot; =&gt; new booleans.BooleanArrayList&lt;br /&gt;    case &quot;byte&quot; =&gt; new bytes.ByteArrayList&lt;br /&gt;    case &quot;char&quot; =&gt; new chars.CharArrayList&lt;br /&gt;    case &quot;double&quot; =&gt; new doubles.DoubleArrayList&lt;br /&gt;    case &quot;float&quot; =&gt; new floats.FloatArrayList&lt;br /&gt;    case &quot;int&quot; =&gt; new ints.IntArrayList&lt;br /&gt;    case &quot;long&quot; =&gt; new longs.LongArrayList&lt;br /&gt;    case &quot;short&quot; =&gt; new shorts.ShortArrayList&lt;br /&gt;    case _ =&gt; new objects.ObjectArrayList[T]&lt;br /&gt;  }).asInstanceOf[java.util.List[T]]&lt;br /&gt;}&lt;/code&gt;&lt;/pre&gt;&lt;/blockquote&gt;Now, invoking the &lt;code&gt;mkList&lt;/code&gt; method with the proper type (i.e., &lt;code&gt;mkList[Int]&lt;/code&gt;, &lt;code&gt;mkList[Double]&lt;/code&gt;, etc.) will create an ArrayList optimized for that particular primitive type. We can verify that the correct classes are being instantiated by doing a little reflection.&lt;br /&gt;&lt;blockquote&gt;&lt;pre&gt;&lt;code&gt;&lt;/code&gt;mkList[Int].getClass.getName&lt;br /&gt;// returns &quot;it.unimi.dsi.fastutil.ints.IntArrayList&quot;&lt;br /&gt;&lt;br /&gt;mkList[Double].getClass.getName&lt;br /&gt;// returns &quot;it.unimi.dsi.fastutil.doubles.DoubleArrayList&quot;&lt;/pre&gt;&lt;/blockquote&gt;These optimized collections can have considerable benefits over their unoptimized counterparts in &lt;code&gt;java.util&lt;/code&gt;. Just imagine, for example, the memory overhead of storing boxed Bytes instead of unboxed bytes. Storing just the pointer for one boxed Byte takes up at least four (and possibly eight) bytes!&lt;br /&gt;&lt;br /&gt;Of course, the same effect could be achieved in Java by passing an explicit java.lang.Class&amp;lt;T&amp;gt; parameter to mkList. The disadvantage is that this imposes a significant overhead on the programmer to create and pass around these Class&amp;lt;T&amp;gt; objects. Scala's support for implicit parameters, and the automatic injection of Manifests by the compiler, makes reifying types on the JVM slightly less painful.&lt;br /&gt;&lt;br /&gt;&lt;span&gt;Appendix: Other Methods on Manifests&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;In this example, the only method we used on Manifests was &lt;code&gt;toString&lt;/code&gt;. What other methods are available? Manifests are as-yet undocumented (not in the official Scaladocs), but looking through the &lt;a href=&quot;http://lampsvn.epfl.ch/trac/scala/browser/scala/tags/R_2_7_2_final/src/library/scala/reflect/Manifest.scala&quot;&gt;source&lt;/a&gt; can give us an idea of what's available.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;erasure&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;This method returns the java.lang.Class that corresponds to the run time erasure of the Scala type represented by the Manifest.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&amp;lt;:&amp;lt;&lt;/code&gt; and &lt;code&gt;&amp;gt;:&amp;gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;These methods test whether the type represented by the Manifest is a subtype or a supertype (respectively) of the type represented by the given parameter. As the source warns, the current implementation is merely an approximation, as it is based on the erasure of the two types.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;equals&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;This method tests whether two types are equal. Again, the source warns that the current implementation is merely an approximation, as it is based on the erasure of the two types.&lt;br /&gt;&lt;br /&gt;&lt;span&gt;Thanks to David Hall for suggesting the example.&lt;/span&gt;</content>
		<author>
			<name>Jorge Ortiz</name>
			<email>noreply@blogger.com</email>
			<uri>http://scala-blogs.org/</uri>
		</author>
		<source>
			<title type="html">Scala Blog</title>
			<link rel="self" href="http://scala-blogs.org/feeds/posts/default?alt=rss"/>
			<id>tag:blogger.com,1999:blog-6374583985636407395</id>
			<updated>2008-12-03T15:20:37+00:00</updated>
		</source>
	</entry>

	<entry xml:lang="en">
		<title type="html">scala.Function1 lacking</title>
		<link href="http://blog.tmorris.net/scalafunction1-lacking/"/>
		<id>http://blog.tmorris.net/?p=471</id>
		<updated>2008-12-03T07:36:51+00:00</updated>
		<content type="html">&lt;p&gt;The Scala API leaves a lot to be desired. I&amp;#8217;m going to pick on a few methods that should appear, but do not, on &lt;code&gt;&lt;a href=&quot;http://www.scala-lang.org/docu/files/api/scala/Function1.html&quot;&gt;scala.Function1&lt;/a&gt;&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;They are:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;map&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;flatMap&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;*&gt;&lt;/code&gt; &lt;a href=&quot;http://en.wikipedia.org/wiki/SKI_combinator_calculus&quot;&gt;(the S combinator)&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;on&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Using some magic with the &lt;code&gt;implicit&lt;/code&gt; keyword I can make it appear as if these methods did in fact exist:&lt;/p&gt;

&lt;div class=&quot;wp_syntax&quot;&gt;&lt;div class=&quot;code&quot;&gt;&lt;pre class=&quot;scala&quot;&gt;&lt;span&gt;sealed&lt;/span&gt; &lt;span&gt;trait&lt;/span&gt; RichFunction1&lt;span&gt;&amp;#91;&lt;/span&gt;-T, +R&lt;span&gt;&amp;#93;&lt;/span&gt; &lt;span&gt;&amp;#123;&lt;/span&gt;
  &lt;span&gt;def&lt;/span&gt; apply&lt;span&gt;&amp;#40;&lt;/span&gt;t&lt;span&gt;:&lt;/span&gt; T&lt;span&gt;&amp;#41;&lt;/span&gt;&lt;span&gt;:&lt;/span&gt; R
&amp;nbsp;
  &lt;span&gt;import&lt;/span&gt; RichFunction1.&lt;span&gt;rich&lt;/span&gt;
&amp;nbsp;
  &lt;span&gt;def&lt;/span&gt; map&lt;span&gt;&amp;#91;&lt;/span&gt;X&lt;span&gt;&amp;#93;&lt;/span&gt;&lt;span&gt;&amp;#40;&lt;/span&gt;g&lt;span&gt;:&lt;/span&gt; R &lt;span&gt;=&amp;gt;&lt;/span&gt; X&lt;span&gt;&amp;#41;&lt;/span&gt; &lt;span&gt;=&lt;/span&gt; rich&lt;span&gt;&amp;#91;&lt;/span&gt;T, X&lt;span&gt;&amp;#93;&lt;/span&gt;&lt;span&gt;&amp;#40;&lt;/span&gt;g compose &lt;span&gt;&amp;#40;&lt;/span&gt;apply&lt;span&gt;&amp;#40;&lt;/span&gt;&lt;span&gt;_&lt;/span&gt;&lt;span&gt;&amp;#41;&lt;/span&gt;&lt;span&gt;&amp;#41;&lt;/span&gt;&lt;span&gt;&amp;#41;&lt;/span&gt;
&amp;nbsp;
  &lt;span&gt;def&lt;/span&gt; flatMap&lt;span&gt;&amp;#91;&lt;/span&gt;TT &lt;span&gt;&amp;lt;:&lt;/span&gt; T, X&lt;span&gt;&amp;#93;&lt;/span&gt;&lt;span&gt;&amp;#40;&lt;/span&gt;g&lt;span&gt;:&lt;/span&gt; R &lt;span&gt;=&amp;gt;&lt;/span&gt; RichFunction1&lt;span&gt;&amp;#91;&lt;/span&gt;TT, X&lt;span&gt;&amp;#93;&lt;/span&gt;&lt;span&gt;&amp;#41;&lt;/span&gt; &lt;span&gt;=&lt;/span&gt;
    rich&lt;span&gt;&amp;#91;&lt;/span&gt;TT, X&lt;span&gt;&amp;#93;&lt;/span&gt;&lt;span&gt;&amp;#40;&lt;/span&gt;t &lt;span&gt;=&amp;gt;&lt;/span&gt; g&lt;span&gt;&amp;#40;&lt;/span&gt;apply&lt;span&gt;&amp;#40;&lt;/span&gt;t&lt;span&gt;&amp;#41;&lt;/span&gt;&lt;span&gt;&amp;#41;&lt;/span&gt;&lt;span&gt;&amp;#40;&lt;/span&gt;t&lt;span&gt;&amp;#41;&lt;/span&gt;&lt;span&gt;&amp;#41;&lt;/span&gt;
&amp;nbsp;
  &lt;span&gt;// The S combinator (SKI)&lt;/span&gt;
  &lt;span&gt;def&lt;/span&gt; &lt;span&gt;&amp;lt;*&amp;gt;&lt;/span&gt;&lt;span&gt;&amp;#91;&lt;/span&gt;TT &lt;span&gt;&amp;lt;:&lt;/span&gt; T, X&lt;span&gt;&amp;#93;&lt;/span&gt;&lt;span&gt;&amp;#40;&lt;/span&gt;f&lt;span&gt;:&lt;/span&gt; RichFunction1&lt;span&gt;&amp;#91;&lt;/span&gt;TT, R &lt;span&gt;=&amp;gt;&lt;/span&gt; X&lt;span&gt;&amp;#93;&lt;/span&gt;&lt;span&gt;&amp;#41;&lt;/span&gt; &lt;span&gt;=&lt;/span&gt; &lt;span&gt;&amp;#40;&lt;/span&gt;t&lt;span&gt;:&lt;/span&gt; TT&lt;span&gt;&amp;#41;&lt;/span&gt; &lt;span&gt;=&amp;gt;&lt;/span&gt; f&lt;span&gt;&amp;#40;&lt;/span&gt;t&lt;span&gt;&amp;#41;&lt;/span&gt;&lt;span&gt;&amp;#40;&lt;/span&gt;apply&lt;span&gt;&amp;#40;&lt;/span&gt;t&lt;span&gt;&amp;#41;&lt;/span&gt;&lt;span&gt;&amp;#41;&lt;/span&gt;
&amp;nbsp;
  &lt;span&gt;// S again, swapped arguments&lt;/span&gt;
  &lt;span&gt;def&lt;/span&gt; &lt;span&gt;&amp;lt;*&amp;gt;:&lt;/span&gt;&lt;span&gt;&amp;#91;&lt;/span&gt;TT &lt;span&gt;&amp;lt;:&lt;/span&gt; T, X&lt;span&gt;&amp;#93;&lt;/span&gt;&lt;span&gt;&amp;#40;&lt;/span&gt;f&lt;span&gt;:&lt;/span&gt; RichFunction1&lt;span&gt;&amp;#91;&lt;/span&gt;TT, R &lt;span&gt;=&amp;gt;&lt;/span&gt; X&lt;span&gt;&amp;#93;&lt;/span&gt;&lt;span&gt;&amp;#41;&lt;/span&gt; &lt;span&gt;=&lt;/span&gt; &lt;span&gt;&amp;lt;*&amp;gt;&lt;/span&gt;&lt;span&gt;&amp;#40;&lt;/span&gt;f&lt;span&gt;&amp;#41;&lt;/span&gt;
&amp;nbsp;
  &lt;span&gt;// map with swapped arguments&lt;/span&gt;
  &lt;span&gt;def&lt;/span&gt; &lt;span&gt;&amp;lt;&lt;/span&gt;-&lt;span&gt;:&lt;/span&gt;&lt;span&gt;&amp;#91;&lt;/span&gt;X&lt;span&gt;&amp;#93;&lt;/span&gt;&lt;span&gt;&amp;#40;&lt;/span&gt;g&lt;span&gt;:&lt;/span&gt; R &lt;span&gt;=&amp;gt;&lt;/span&gt; X&lt;span&gt;&amp;#41;&lt;/span&gt; &lt;span&gt;=&lt;/span&gt; map&lt;span&gt;&amp;#40;&lt;/span&gt;g&lt;span&gt;&amp;#41;&lt;/span&gt;
&amp;nbsp;
  &lt;span&gt;def&lt;/span&gt; on&lt;span&gt;&amp;#91;&lt;/span&gt;K&lt;span&gt;&amp;#93;&lt;/span&gt;&lt;span&gt;&amp;#40;&lt;/span&gt;f&lt;span&gt;:&lt;/span&gt; &lt;span&gt;&amp;#40;&lt;/span&gt;R, R&lt;span&gt;&amp;#41;&lt;/span&gt; &lt;span&gt;=&amp;gt;&lt;/span&gt; K, t1&lt;span&gt;:&lt;/span&gt; T, t2&lt;span&gt;:&lt;/span&gt; T&lt;span&gt;&amp;#41;&lt;/span&gt;&lt;span&gt;:&lt;/span&gt; K &lt;span&gt;=&lt;/span&gt; f&lt;span&gt;&amp;#40;&lt;/span&gt;apply&lt;span&gt;&amp;#40;&lt;/span&gt;t1&lt;span&gt;&amp;#41;&lt;/span&gt;, apply&lt;span&gt;&amp;#40;&lt;/span&gt;t2&lt;span&gt;&amp;#41;&lt;/span&gt;&lt;span&gt;&amp;#41;&lt;/span&gt;
&lt;span&gt;&amp;#125;&lt;/span&gt;
&amp;nbsp;
&lt;span&gt;object&lt;/span&gt; RichFunction1 &lt;span&gt;&amp;#123;&lt;/span&gt;
  &lt;span&gt;implicit&lt;/span&gt; &lt;span&gt;def&lt;/span&gt; rich&lt;span&gt;&amp;#91;&lt;/span&gt;T, R&lt;span&gt;&amp;#93;&lt;/span&gt;&lt;span&gt;&amp;#40;&lt;/span&gt;f&lt;span&gt;:&lt;/span&gt; T &lt;span&gt;=&amp;gt;&lt;/span&gt; R&lt;span&gt;&amp;#41;&lt;/span&gt; &lt;span&gt;=&lt;/span&gt; &lt;span&gt;new&lt;/span&gt; RichFunction1&lt;span&gt;&amp;#91;&lt;/span&gt;T, R&lt;span&gt;&amp;#93;&lt;/span&gt; &lt;span&gt;&amp;#123;&lt;/span&gt;
    &lt;span&gt;def&lt;/span&gt; apply&lt;span&gt;&amp;#40;&lt;/span&gt;t&lt;span&gt;:&lt;/span&gt; T&lt;span&gt;&amp;#41;&lt;/span&gt; &lt;span&gt;=&lt;/span&gt; f&lt;span&gt;&amp;#40;&lt;/span&gt;t&lt;span&gt;&amp;#41;&lt;/span&gt;
  &lt;span&gt;&amp;#125;&lt;/span&gt;
&lt;span&gt;&amp;#125;&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;By having &lt;code&gt;flatMap&lt;/code&gt; (and therefore &lt;code&gt;map&lt;/code&gt;) this allows you to remove a lot of duplication. This may come at the expense of syntactical noise per Scala, but not always. Suppose you were given a String and you wanted to check if it was equal to one of a few Strings (ignoring case). You could use some trickery with existing methods on &lt;code&gt;List&lt;/code&gt;, but I want to keep this example simple, so let us ignore that possibility for now (and accept that I could come up with a sufficient example that such trickery is insufficient).&lt;/p&gt;

&lt;div class=&quot;wp_syntax&quot;&gt;&lt;div class=&quot;code&quot;&gt;&lt;pre class=&quot;scala&quot;&gt;  &lt;span&gt;// For example, suppose this predicate function&lt;/span&gt;
  &lt;span&gt;def&lt;/span&gt; predicate&lt;span&gt;&amp;#40;&lt;/span&gt;s1&lt;span&gt;:&lt;/span&gt; String&lt;span&gt;&amp;#41;&lt;/span&gt; &lt;span&gt;=&lt;/span&gt; s1 equalsIgnoreCase &lt;span&gt;&amp;#40;&lt;/span&gt;&lt;span&gt;_:&lt;/span&gt; String&lt;span&gt;&amp;#41;&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Here is the repetition&lt;/p&gt;

&lt;div class=&quot;wp_syntax&quot;&gt;&lt;div class=&quot;code&quot;&gt;&lt;pre class=&quot;scala&quot;&gt;  &lt;span&gt;// predicate(s, _) repeats&lt;/span&gt;
  &lt;span&gt;def&lt;/span&gt; f&lt;span&gt;&amp;#40;&lt;/span&gt;s&lt;span&gt;:&lt;/span&gt; String&lt;span&gt;&amp;#41;&lt;/span&gt; &lt;span&gt;=&lt;/span&gt; predicate&lt;span&gt;&amp;#40;&lt;/span&gt;&lt;span&gt;&amp;quot;x&amp;quot;&lt;/span&gt;&lt;span&gt;&amp;#41;&lt;/span&gt;&lt;span&gt;&amp;#40;&lt;/span&gt;s&lt;span&gt;&amp;#41;&lt;/span&gt; || predicate&lt;span&gt;&amp;#40;&lt;/span&gt;&lt;span&gt;&amp;quot;y&amp;quot;&lt;/span&gt;&lt;span&gt;&amp;#41;&lt;/span&gt;&lt;span&gt;&amp;#40;&lt;/span&gt;s&lt;span&gt;&amp;#41;&lt;/span&gt; || predicate&lt;span&gt;&amp;#40;&lt;/span&gt;&lt;span&gt;&amp;quot;z&amp;quot;&lt;/span&gt;&lt;span&gt;&amp;#41;&lt;/span&gt;&lt;span&gt;&amp;#40;&lt;/span&gt;s&lt;span&gt;&amp;#41;&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;But if we have &lt;code&gt;flatMap&lt;/code&gt; and &lt;code&gt;map&lt;/code&gt; we can use a for-comprehension:&lt;/p&gt;

&lt;div class=&quot;wp_syntax&quot;&gt;&lt;div class=&quot;code&quot;&gt;&lt;pre class=&quot;scala&quot;&gt;  &lt;span&gt;// Taking advantage of flatMap/map&lt;/span&gt;
  &lt;span&gt;val&lt;/span&gt; g &lt;span&gt;=&lt;/span&gt; &lt;span&gt;for&lt;/span&gt;&lt;span&gt;&amp;#40;&lt;/span&gt;a &lt;span&gt;&amp;lt;&lt;/span&gt;- predicate&lt;span&gt;&amp;#40;&lt;/span&gt;&lt;span&gt;&amp;quot;x&amp;quot;&lt;/span&gt;&lt;span&gt;&amp;#41;&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;
              b &lt;span&gt;&amp;lt;&lt;/span&gt;- predicate&lt;span&gt;&amp;#40;&lt;/span&gt;&lt;span&gt;&amp;quot;y&amp;quot;&lt;/span&gt;&lt;span&gt;&amp;#41;&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;
              c &lt;span&gt;&amp;lt;&lt;/span&gt;- predicate&lt;span&gt;&amp;#40;&lt;/span&gt;&lt;span&gt;&amp;quot;z&amp;quot;&lt;/span&gt;&lt;span&gt;&amp;#41;&lt;/span&gt;&lt;span&gt;&amp;#41;&lt;/span&gt;
          &lt;span&gt;yield&lt;/span&gt; a || b || c&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Here is how that same code looks when expanded:&lt;/p&gt;

&lt;div class=&quot;wp_syntax&quot;&gt;&lt;div class=&quot;code&quot;&gt;&lt;pre class=&quot;scala&quot;&gt;  &lt;span&gt;// Expansion of g&lt;/span&gt;
  &lt;span&gt;val&lt;/span&gt; h &lt;span&gt;=&lt;/span&gt; predicate&lt;span&gt;&amp;#40;&lt;/span&gt;&lt;span&gt;&amp;quot;x&amp;quot;&lt;/span&gt;&lt;span&gt;&amp;#41;&lt;/span&gt; flatMap &lt;span&gt;&amp;#40;&lt;/span&gt;a &lt;span&gt;=&amp;gt;&lt;/span&gt;
          predicate&lt;span&gt;&amp;#40;&lt;/span&gt;&lt;span&gt;&amp;quot;y&amp;quot;&lt;/span&gt;&lt;span&gt;&amp;#41;&lt;/span&gt; flatMap &lt;span&gt;&amp;#40;&lt;/span&gt;b &lt;span&gt;=&amp;gt;&lt;/span&gt;
          predicate&lt;span&gt;&amp;#40;&lt;/span&gt;&lt;span&gt;&amp;quot;z&amp;quot;&lt;/span&gt;&lt;span&gt;&amp;#41;&lt;/span&gt; map &lt;span&gt;&amp;#40;&lt;/span&gt;&lt;span&gt;&amp;#40;&lt;/span&gt;c &lt;span&gt;=&amp;gt;&lt;/span&gt;
            a || b || c&lt;span&gt;&amp;#41;&lt;/span&gt;&lt;span&gt;&amp;#41;&lt;/span&gt;&lt;span&gt;&amp;#41;&lt;/span&gt;&lt;span&gt;&amp;#41;&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;How about some fancy stuff with the S combinator (&lt;code&gt;&amp;lt;*&gt;&lt;/code&gt;):&lt;/p&gt;

&lt;div class=&quot;wp_syntax&quot;&gt;&lt;div class=&quot;code&quot;&gt;&lt;pre class=&quot;scala&quot;&gt;  &lt;span&gt;val&lt;/span&gt; or &lt;span&gt;=&lt;/span&gt; Function.&lt;span&gt;curried&lt;/span&gt;&lt;span&gt;&amp;#40;&lt;/span&gt;&lt;span&gt;&amp;#40;&lt;/span&gt;&lt;span&gt;_:&lt;/span&gt; &lt;span&gt;Boolean&lt;/span&gt;&lt;span&gt;&amp;#41;&lt;/span&gt; || &lt;span&gt;&amp;#40;&lt;/span&gt;&lt;span&gt;_:&lt;/span&gt; &lt;span&gt;Boolean&lt;/span&gt;&lt;span&gt;&amp;#41;&lt;/span&gt; || &lt;span&gt;&amp;#40;&lt;/span&gt;&lt;span&gt;_:&lt;/span&gt; &lt;span&gt;Boolean&lt;/span&gt;&lt;span&gt;&amp;#41;&lt;/span&gt;&lt;span&gt;&amp;#41;&lt;/span&gt;
&amp;nbsp;
  &lt;span&gt;// Using the S combinator&lt;/span&gt;
  &lt;span&gt;val&lt;/span&gt; i &lt;span&gt;=&lt;/span&gt; predicate&lt;span&gt;&amp;#40;&lt;/span&gt;&lt;span&gt;&amp;quot;z&amp;quot;&lt;/span&gt;&lt;span&gt;&amp;#41;&lt;/span&gt; &lt;span&gt;&amp;lt;*&amp;gt;&lt;/span&gt;
          &lt;span&gt;&amp;#40;&lt;/span&gt;predicate&lt;span&gt;&amp;#40;&lt;/span&gt;&lt;span&gt;&amp;quot;y&amp;quot;&lt;/span&gt;&lt;span&gt;&amp;#41;&lt;/span&gt; &lt;span&gt;&amp;lt;*&amp;gt;&lt;/span&gt;
          &lt;span&gt;&amp;#40;&lt;/span&gt;predicate&lt;span&gt;&amp;#40;&lt;/span&gt;&lt;span&gt;&amp;quot;x&amp;quot;&lt;/span&gt;&lt;span&gt;&amp;#41;&lt;/span&gt; map
          or&lt;span&gt;&amp;#41;&lt;/span&gt;&lt;span&gt;&amp;#41;&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Or with the arguments swapped around:&lt;/p&gt;

&lt;div class=&quot;wp_syntax&quot;&gt;&lt;div class=&quot;code&quot;&gt;&lt;pre class=&quot;scala&quot;&gt;  &lt;span&gt;// Using S with swapped arguments&lt;/span&gt;
  &lt;span&gt;val&lt;/span&gt; j &lt;span&gt;=&lt;/span&gt; &lt;span&gt;&amp;#40;&lt;/span&gt;&lt;span&gt;&amp;#40;&lt;/span&gt;or &lt;span&gt;&amp;lt;&lt;/span&gt;-&lt;span&gt;:&lt;/span&gt; predicate&lt;span&gt;&amp;#40;&lt;/span&gt;&lt;span&gt;&amp;quot;x&amp;quot;&lt;/span&gt;&lt;span&gt;&amp;#41;&lt;/span&gt;&lt;span&gt;&amp;#41;&lt;/span&gt; &lt;span&gt;&amp;lt;*&amp;gt;:&lt;/span&gt; predicate&lt;span&gt;&amp;#40;&lt;/span&gt;&lt;span&gt;&amp;quot;y&amp;quot;&lt;/span&gt;&lt;span&gt;&amp;#41;&lt;/span&gt;&lt;span&gt;&amp;#41;&lt;/span&gt; &lt;span&gt;&amp;lt;*&amp;gt;:&lt;/span&gt; predicate&lt;span&gt;&amp;#40;&lt;/span&gt;&lt;span&gt;&amp;quot;z&amp;quot;&lt;/span&gt;&lt;span&gt;&amp;#41;&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Pretty neat eh?&lt;/p&gt;
&lt;p&gt;Suppose you wanted to check if the length of one List was less than the length of another. You might be tempted to write &lt;code&gt;x.length &amp;lt; y.length&lt;/code&gt;. Notice how &lt;code&gt;_.length&lt;/code&gt; repeats? Again I want to keep this example simple so while the solution below is more noisy, there are cases where it is not. &lt;/p&gt;
&lt;p&gt;Scala is let down a little by first-class function semantics. We&amp;#8217;ll begin with assuming this first-class function value:&lt;/p&gt;

&lt;div class=&quot;wp_syntax&quot;&gt;&lt;div class=&quot;code&quot;&gt;&lt;pre class=&quot;scala&quot;&gt;  &lt;span&gt;val&lt;/span&gt; length &lt;span&gt;=&lt;/span&gt; &lt;span&gt;&amp;#40;&lt;/span&gt;&lt;span&gt;_:&lt;/span&gt; List&lt;span&gt;&amp;#91;&lt;/span&gt;&lt;span&gt;Int&lt;/span&gt;&lt;span&gt;&amp;#93;&lt;/span&gt;&lt;span&gt;&amp;#41;&lt;/span&gt;.&lt;span&gt;length&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Then comparing using length:&lt;/p&gt;

&lt;div class=&quot;wp_syntax&quot;&gt;&lt;div class=&quot;code&quot;&gt;&lt;pre class=&quot;scala&quot;&gt;  &lt;span&gt;val&lt;/span&gt; k &lt;span&gt;=&lt;/span&gt; length on &lt;span&gt;&amp;#40;&lt;/span&gt;&lt;span&gt;_&lt;/span&gt; &lt;span&gt;&amp;lt;&lt;/span&gt; &lt;span&gt;_&lt;/span&gt;, List&lt;span&gt;&amp;#40;&lt;/span&gt;&lt;span&gt;4&lt;/span&gt;, &lt;span&gt;5&lt;/span&gt;, &lt;span&gt;6&lt;/span&gt;, &lt;span&gt;7&lt;/span&gt;&lt;span&gt;&amp;#41;&lt;/span&gt;, List&lt;span&gt;&amp;#40;&lt;/span&gt;&lt;span&gt;1&lt;/span&gt;, &lt;span&gt;2&lt;/span&gt;, &lt;span&gt;3&lt;/span&gt;&lt;span&gt;&amp;#41;&lt;/span&gt;&lt;span&gt;&amp;#41;&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;A bit noisier but the repetition is gone. It&amp;#8217;s a shame that abstraction comes at a syntactic cost and in some cases it may even be worth that cost. I wish I had the choice.&lt;/p&gt;</content>
		<author>
			<name>Tony Morris</name>
			<uri>http://blog.tmorris.net</uri>
		</author>
		<source>
			<title type="html">λ Tony’s blog λ</title>
			<subtitle type="html">The weblog of Tony Morris</subtitle>
			<link rel="self" href="http://blog.tmorris.net/feed/"/>
			<id>http://blog.tmorris.net/feed/</id>
			<updated>2008-12-03T07:40:30+00:00</updated>
		</source>
	</entry>

	<entry>
		<title type="html">G1 Camera Tricks</title>
		<link href="http://bytecrafter.blogspot.com/2008/12/g1-camera-tricks.html"/>
		<id>tag:blogger.com,1999:blog-32241238.post-8180968040451047552</id>
		<updated>2008-12-02T23:25:08+00:00</updated>
		<content type="html">&lt;p&gt;The G1's camera seems to be slow. Really slow. As in several-seconds slow. I always wondered why; then I started to look at my pictures from the Macy's Thanksgiving Day Parade.&lt;/p&gt;&lt;a href=&quot;http://4.bp.blogspot.com/_yWS30lH8nfY/STYGEAhHYkI/AAAAAAAAAGE/If1DsgmVDKg/s1600-h/1227796151134.jpg&quot;&gt;&lt;img src=&quot;http://4.bp.blogspot.com/_yWS30lH8nfY/STYGEAhHYkI/AAAAAAAAAGE/If1DsgmVDKg/s400/1227796151134.jpg&quot; border=&quot;0&quot; alt=&quot;&quot; id=&quot;BLOGGER_PHOTO_ID_5275410679439254082&quot; /&gt;&lt;/a&gt;&lt;p&gt;Ah. I see. I don't think that's because of the curvature of the lens (it's not curved THAT much) I was apparently panning the camera when I took this picture (to keep up with the float, though I didn't correctly account for the very long shutter delay, and the float ended up behind the pole). You are seeing the effect of the CCD &quot;scanning&quot;. This reminds me of &lt;a href=&quot;http://www.sentex.net/~mwandel/tech/scanner.html&quot; title=&quot;Building scanning camera from a flatbed scanner&quot;&gt;this project&lt;/a&gt;, in which a dude builds a digital camera from a flatbed scanner. &lt;img src=&quot;http://www.sentex.net/~mwandel/tech/wacky_garage.jpg&quot; /&gt; This is a picture of his garage door opening and closing while he takes a single exposure.&lt;/p&gt;&lt;p&gt;I hope this isn't an actual limitation of the G1's hardware. My cheap &lt;a href=&quot;http://europe.nokia.com/A4430608&quot; title=&quot;Nokia Europe - Nokia 6267 - Technical specifications&quot;&gt;Nokia 6267&lt;/a&gt;, a feature phone, had an excellent 2MP camera that took pictures nearly instantaneously. So far, the G1's camera reminds me of my short experience with Windows Mobile 5's camera app - slow and clunky.&lt;/p&gt;</content>
		<author>
			<name>Daniel Yankowsky</name>
			<email>noreply@blogger.com</email>
			<uri>http://bytecrafter.blogspot.com/</uri>
		</author>
		<source>
			<title type="html">Why not?</title>
			<link rel="self" href="http://bytecrafter.blogspot.com/feeds/posts/default"/>
			<id>tag:blogger.com,1999:blog-32241238</id>
			<updated>2008-12-03T04:40:57+00:00</updated>
		</source>
	</entry>

	<entry>
		<title type="html">Using a Horizontal Progress Bar in Android</title>
		<link href="http://bytecrafter.blogspot.com/2008/12/using-horizontal-progress-bar-in.html"/>
		<id>tag:blogger.com,1999:blog-32241238.post-5000499182921486376</id>
		<updated>2008-12-02T23:05:13+00:00</updated>
		<content type="html">&lt;p&gt;I was working on my Android downloader application yesterday, when I ran into a bit of a snag. I wanted to display a list of downloads (similar to the Firefox downloads window). Each item in the list should show the file name and a horizontal progress bar. I started to implement this, and several hours later stumbled upon the archaic solution. I wanted to share this, both to help anybody who may be trying to do something similar, and also to illustrate how the lack of good documentation is hurting aspiring Android developers.&lt;/p&gt;&lt;p&gt;I thought that I could put a &lt;a href=&quot;http://code.google.com/android/reference/android/widget/ProgressBar.html&quot; title=&quot;android.widget.ProgressBar - Android&quot;&gt;ProgressBar&lt;/a&gt; instance in my xml, set it to be indeterminate, give it a max and a value, and be done. However, it wasn't nearly that easy. After a few hours of hunting on Google and the Android Groups, I stumbled upon the solution in an &lt;a href=&quot;http://books.google.com/books?id=lrf4xxsgmd8C&amp;pg=PA127&amp;lpg=PA127&amp;dq=android+horizontal+progress+bar&amp;source=web&amp;ots=yuCKvJxT29&amp;sig=X1k2Y6AUBNKnpH2UtrP1xXOYEmI&amp;hl=en&amp;sa=X&amp;oi=book_result&amp;resnum=2&amp;ct=result#PPA125&quot; title=&quot;The Busy Coder's Guide to Android ... - Google Book Search&quot;&gt;online preview&lt;/a&gt; of &lt;a href=&quot;http://commonsware.com/Android/&quot; title=&quot;CommonsWare: The Busy Coder's Guide to Android Development&quot;&gt;The Busy Coder's Guide to Android Development&lt;/a&gt;. In short, I had to set the following on my ProgressBar's XML:&lt;pre class=&quot;code&quot;&gt;style=&quot;?android:attr/progressBarStyleHorizontal&quot;&lt;/pre&gt;WTF?&lt;/p&gt;&lt;p&gt;Let's try to break this down. The ? on the front indicates that this is a reference to something in the current theme. What is a theme? Well, Android's UI infrastructure is similar to Swing or HTML in that it tries to accommodate components whose size is not known until runtime. Android's components are also themeable (similar to the Swing &lt;a href=&quot;http://www.ibm.com/developerworks/java/library/j-synth/&quot; title=&quot;Advanced Synth&quot;&gt;Synth LAF&lt;/a&gt;). A theme is a collection of related component styles. You can control the theme used by your application &lt;a href=&quot;http://code.google.com/android/reference/android/R.styleable.html#AndroidManifestApplication_theme&quot; title=&quot;android.R.styleable - Android&quot;&gt;in the AndroidManifest.xml file&lt;/a&gt;. So, I think we can safely conclude that attr/progressBarStyleHorizontal is something whose actual value is defined in a particular theme.&lt;/p&gt;&lt;p&gt;If you take a peek in the &lt;a href=&quot;http://source.android.com/&quot; title=&quot;Welcome ‎(Android Open Source Project‎)&quot;&gt;android source code&lt;/a&gt;, inside frameworks/base/core/res/res/values/attrs.xml, you will find the following definition:&lt;pre class=&quot;code&quot;&gt;&amp;lt;resources&amp;gt;&lt;br /&gt;    &amp;lt;declare-styleable name=&quot;Theme&quot;&amp;gt;&lt;br /&gt;        &amp;lt;!-- snip --&amp;gt;&lt;br /&gt;        &amp;lt;attr name=&quot;progressBarStyleHorizontal&quot; format=&quot;reference&quot; /&amp;gt;&lt;br /&gt;&lt;/pre&gt;OK, not very useful. However, in frameworks/base/core/res/res/values/themes.xml, we find:&lt;pre class=&quot;code&quot;&gt;&amp;lt;resources&amp;gt;&lt;br /&gt;    &amp;lt;style name=&quot;Theme&quot;&amp;gt;&lt;br /&gt;        &amp;lt;item name=&quot;progressBarStyleHorizontal&quot;&amp;gt;@android:style/Widget.ProgressBar.Horizontal&amp;lt;/item&amp;gt;&lt;br /&gt;&lt;/pre&gt;Nowe we're getting somewhere. Finally, inside frameworks/base/core/res/res/values/styles.xml, we see:&lt;pre class=&quot;code&quot;&gt;&amp;lt;resources&amp;gt;&lt;br /&gt;    &amp;lt;style name=&quot;Widget.ProgressBar.Horizontal&quot;&amp;gt;&lt;br /&gt;        &amp;lt;item name=&quot;android:indeterminateOnly&quot;&amp;gt;false&amp;lt;/item&amp;gt;&lt;br /&gt;        &amp;lt;item name=&quot;android:progressDrawable&quot;&amp;gt;@android:drawable/progress_horizontal&amp;lt;/item&amp;gt;&lt;br /&gt;        &amp;lt;item name=&quot;android:indeterminateDrawable&quot;&amp;gt;@android:drawable/progress_indeterminate_horizontal&amp;lt;/item&amp;gt;&lt;br /&gt;        &amp;lt;item name=&quot;android:minHeight&quot;&amp;gt;20dip&amp;lt;/item&amp;gt;&lt;br /&gt;        &amp;lt;item name=&quot;android:maxHeight&quot;&amp;gt;20dip&amp;lt;/item&amp;gt;&lt;br /&gt;    &amp;lt;/style&amp;gt;&lt;br /&gt;&lt;/pre&gt;&lt;/p&gt;&lt;p&gt;What's going on here? Well, it looks like themes.xml defines a theme as a collection of styles. Along with that, styles.xml specifies a set of attributes that should be applied to a particular XML element. By saying &lt;pre class=&quot;code&quot;&gt;&amp;lt;ProgressBar style=&quot;?android:attr/progressBarStyleHorizontal&quot;&amp;gt;&lt;/pre&gt; we are really saying &lt;pre class=&quot;code&quot;&gt;&amp;lt;ProgressBar style=&quot;@android:style/Widget.ProgressBar.Horizontal&quot;&amp;gt;&lt;/pre&gt; which is like saying &lt;pre class=&quot;code&quot;&gt;&amp;lt;ProgressBar &lt;br /&gt;    android:indeterminateOnly=&quot;false&quot; &lt;br /&gt;    android:progressDrawable=&quot;@android:drawable/progress_horizontal&quot; &lt;br /&gt;    android:indeterminateDrawable=&quot;@android:drawable/progress_indeterminate_horizontal&quot; &lt;br /&gt;    android:minHeight=&quot;20dip&quot; &lt;br /&gt;    android:maxHeight=&quot;20dip&quot;&amp;gt;&lt;/pre&gt;Spiffy.&lt;/p&gt;&lt;p&gt;For bonus points, we can look in frameworks/base/core/res/res/drawable/progress_horizontal.xml. This file apparently contains the declarative expression of the horizontal scrollbar graphic. I don't know how extensive this syntax is, but a quick peek at progress_indeterminate_horizontal.xml indicates that it is possible to specify animations in this XML file format.&lt;/p&gt;&lt;p&gt;All this seems really powerful, only somewhat useful, and totally confusing. All I wanted was to create a horizontal progress bar. I can't tell why the Android widget collection includes only one ProgressBar class that is meant to be used for horizontal, indeterminate horizontal, indeterminate circular, and every other kind of possible progress indicator. Perhaps there would be duplication of code if those were separated into different classes. Whatever. I actually don't mind that they stuffed all those progress indicators into a single class. There are some questionable decisions (like having both indeterminate and indeterminateOnly), but I can deal with it. On the other hand, the incantations that you have to use to get the Progress Bar to behave are truly archaic. I think I have proven in this blog post that there is some method to the madness and, as is often the case, easy access to the source code is a must. What bothers me most is that there was absolutely no documentation on the subject. Google seems silent on this topic, and even The Busy Coder's Guide mentions that the style attribute won't be covered until a later edition of the book (though it is possible that the Google Books sample chapter is out of date at this point).&lt;/p&gt;&lt;p&gt;I still maintain that Android is one of the most unique application systems that I've seen. However, as I've tried to develop for it, I have encountered a general lack of polish. Many things that you want to do as a developer are confusing and poorly documented. Familiarity with existing technologies (such as Swing or Applet programming) is pretty much useless here. On the other hand, the core concepts (such as the use of Intents to start applications and communicate between processes, the HEAVY use of message passing, and the declarative nature of the AndroidManifest.xml file) seem to be an excellent base upon which to build not just an open operating system, but a truly open user experience. A power user can really replace virtually any aspect of the system. Perhaps developers will create third party libraries that make Android a little easier within which to develop, or maybe Google itself will provide simpler interfaces for developers. Or perhaps Android will die out because developers had a difficult time building anything particularly complex. Whatever the outcome, I'm excited for the ride.&lt;/p&gt;</content>
		<author>
			<name>Daniel Yankowsky</name>
			<email>noreply@blogger.com</email>
			<uri>http://bytecrafter.blogspot.com/</uri>
		</author>
		<source>
			<title type="html">Why not?</title>
			<link rel="self" href="http://bytecrafter.blogspot.com/feeds/posts/default"/>
			<id>tag:blogger.com,1999:blog-32241238</id>
			<updated>2008-12-03T04:40:57+00:00</updated>
		</source>
	</entry>

	<entry>
		<title type="html">Debugging inside the Scala Eclipse Interpreter</title>
		<link href="http://suereth.blogspot.com/2008/12/debugging-inside-scala-eclipse.html"/>
		<id>tag:blogger.com,1999:blog-1673113361032868171.post-1697327258725593370</id>
		<updated>2008-12-02T17:32:36+00:00</updated>
		<content type="html">So today we didn't have a babysitter, so I took the day to spend time with my daughter.  It was quite fun, and I actually had a chance to get to some of the scala development work I've been meaning to during her nap.&lt;br /&gt;&lt;br /&gt;Specifically, there have been a bunch of bugs with the Scala Eclipse plugin that really fall under contributions I've submitted.  Primarily relating to the Interpreter.&lt;br /&gt;&lt;br /&gt;After spending quite a long time getting my SDT development workspace working again (seriously... I have no idea why it's so hard to make it work on windows, but it is), I was up and running.  In about 20 minutes I managed to convert the original &quot;roll-my-own jvm executor&quot; to use Eclipse JDT's &quot;Launch Configuration&quot; support for a JVM.  Not only does this let people specify nice things like JVM arguments, it also rolls in the ability to actively debug.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Here's a screenshot of a workspace working off my locally installed scala plugin:&lt;br /&gt;&lt;a href=&quot;http://3.bp.blogspot.com/_zY6AYwdFmgA/STW08nXdH6I/AAAAAAAAABs/cZk8_VCkfq0/s1600-h/real-debug%2Binterpret.png&quot;&gt;&lt;img src=&quot;http://3.bp.blogspot.com/_zY6AYwdFmgA/STW08nXdH6I/AAAAAAAAABs/cZk8_VCkfq0/s320/real-debug%2Binterpret.png&quot; border=&quot;0&quot; alt=&quot;&quot; id=&quot;BLOGGER_PHOTO_ID_5275321491986915234&quot; /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Hopefully this will make it into the trunk in a few weeks, depending on how much free time I can find.  There's still a few things I need to work out such as:&lt;br /&gt;&lt;ul&gt;&lt;br /&gt;  &lt;li&gt; Wiring the old menu-style invocation to work with the new LaunchConfiguration&lt;/li&gt;&lt;br /&gt;  &lt;li&gt; Fixing/Tweaking the Launch Configuration Dialog to get rid of wonky behavior and allow configuration of things that matter&lt;/li&gt;&lt;br /&gt;  &lt;li&gt; Allow &quot;bootstrap&quot; code to send to the interpreter &lt;/li&gt;&lt;br /&gt;  &lt;li&gt; Ensure jline works correctly and eclipse passes down &quot;interesting&quot; keystrokes, OR roll my own &lt;/li&gt;&lt;br /&gt;  &lt;li&gt; Figure out how to wire into the syntax highlighter for a console &lt;/li&gt;&lt;br /&gt;&lt;/ul&gt;&lt;br /&gt;&lt;br /&gt;As you can see... it's already an extensive list.  I figure I'll at least get the basics done for the next release (2.8 I guess?)&lt;br /&gt;&lt;br /&gt;Anyway, if anyone wants to try out the code locally, let me know and I'll send you a .patch.</content>
		<author>
			<name>J. Suereth</name>
			<email>noreply@blogger.com</email>
			<uri>http://suereth.blogspot.com/</uri>
		</author>
		<source>
			<title type="html">Rants, Raves and Ridicule</title>
			<subtitle type="html">My thoughts and/or rants on Software Development.</subtitle>
			<link rel="self" href="http://suereth.blogspot.com/feeds/posts/default"/>
			<id>tag:blogger.com,1999:blog-1673113361032868171</id>
			<updated>2008-12-02T22:40:37+00:00</updated>
		</source>
	</entry>

	<entry>
		<title type="html">Cross-platform dressing not always a travesty</title>
		<link href="http://technically.us/code/x/cross-platform-dressing-interfaces-not-always-a-travesty"/>
		<id>http://technically.us/code/x/cross-platform-dressing-interfaces-not-always-a-travesty</id>
		<updated>2008-12-02T14:07:00+00:00</updated>
		<content type="html">&lt;p&gt;&lt;strong&gt;Friday&lt;/strong&gt; is a news reader that is fed by an obscure, non-Google service known as &amp;#8220;NewsGator,&amp;#8221; &lt;a href=&quot;http://technically.us/code/x/friday-a-feed-reader-for-castaways/&quot;&gt;as explained in last week&amp;#8217;s post&lt;/a&gt;. And so many things have happened since then! The technology that drives Friday&amp;#8217;s visuals, &lt;a href=&quot;http://processing.org/&quot;&gt;Processing&lt;/a&gt;, had a splashy 1.0 release. The Thanksgiving holiday was observed in the United States and we proved once more that our domestic travel infrastructure &lt;em&gt;does not scale&lt;/em&gt;. Then on &amp;#8220;Black&amp;#8221; Friday, a Wal-Mart employee was trampled to death in a stampede of discount shoppers. All the while &lt;em&gt;our&lt;/em&gt; Friday related these stories with unflappable grace and charm.&lt;/p&gt;

&lt;p class=&quot;break&quot;&gt; In celebration and exhaustion, let&amp;#8217;s take this opportunity to write an easy post with lots of pictures.&lt;/p&gt;

&lt;p class=&quot;break&quot;&gt; &lt;img src=&quot;http://technically.us/resources/com.typeturner.Typeturner/image?name=friday-win&quot; alt=&quot;Friday on Windows XP&quot; /&gt;&lt;/p&gt;

&lt;h3 id=&quot;platform_swingers&quot;&gt;Platform swingers&lt;/h3&gt;

&lt;p&gt;In the opera of Java, the tragicomic figure of Swing is rivaled in pathos only by &lt;a href=&quot;https://duke.dev.java.net/images/misc/SwingingDuke.png&quot;&gt;El Duque himself (riding a swing)&lt;/a&gt;. Swing was conceived in the midst of an object-oriented resource-based interface revolution, but the toolkit somehow &lt;a href=&quot;http://technically.us/code/x/tales-from-the-desktop-java-crypt/&quot;&gt;managed to escape the paradigm&lt;/a&gt; that would have made it an unmitigated success. Instead, it opted for interface definition in code, which is great for writing &lt;em&gt;Hello World&lt;/em&gt; and terrible for &lt;em&gt;Usable Application&lt;/em&gt;. Ten years later Swing is popular for internal corporate apps that employees must use, or be fired.&lt;/p&gt;

&lt;p&gt;Processing doesn&amp;#8217;t advertise any support for traditional graphical user interface controls, because that is not its bag. The recommended way to do anything so boring is to embed the sketch inside a larger externally coded application, which is great for people that would rather work in an &lt;abbr&gt;IDE&lt;/abbr&gt; anyway. But Friday and its Swing setup screen are developed entirely within the &lt;abbr title=&quot;Processing Development Environment&quot;&gt;PDE&lt;/abbr&gt; (the &lt;a href=&quot;http://technically.us/code/x/runaway-processing/&quot;&gt;Spde&lt;/a&gt; fork of it), because why crash the party with an &lt;abbr&gt;IDE&lt;/abbr&gt; for something so simple?&lt;/p&gt;

&lt;p class=&quot;break&quot;&gt; &lt;img src=&quot;http://technically.us/resources/com.typeturner.Typeturner/image?name=friday-ubuntu&quot; alt=&quot;Friday on Ubuntu XP&quot; /&gt;&lt;/p&gt;

&lt;p class=&quot;break&quot;&gt;One useful trick for apps with such a setup screen is to return false for &lt;a href=&quot;http://dev.processing.org/reference/core/javadoc/processing/core/PApplet.html#displayable()&quot;&gt;&lt;code&gt;displayable&lt;/code&gt;&lt;/a&gt; in the main sketch class, so the sketch window won&amp;#8217;t display until you tell it to. To pop up a separate Swing frame, it&amp;#8217;s just a matter of instantiating the object and setting it to visible. Here is some &lt;a href=&quot;http://www.scala-lang.org/docu/files/api/scala/swing$package.html&quot;&gt;scala-swing&lt;/a&gt; code to lay out the first three elements of Friday&amp;#8217;s setup frame:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;contents = new GridBagPanel {
  add(new Label(&amp;quot;NewsGator Account&amp;quot;) {
    font = font.deriveFont(java.awt.Font.BOLD)
  }, new Constraints {
    gridwidth = 2
    anchor = Anchor.West
    insets = new Insets(0, 0, 30, 0)
  })
  add(new Label(&amp;quot;Don’t have an account?&amp;quot;), new Constraints {
    gridwidth = 2
    gridy = 1
    anchor = Anchor.West
    insets = new Insets(0, 0, 5, 0)
  })
  add(new Button(&amp;quot;Sign Up…&amp;quot;) {
    reactions += {
      case ButtonClicked(_) =&amp;gt; 
        link(&amp;quot;http://www.newsgator.com/ngs/order1.aspx&amp;quot;)
        name_field.requestFocus()
    }
  }, new Constraints {
    gridwidth = 2
    gridy = 2
    anchor = Anchor.West
    insets = new Insets(0, 0, 30, 0)
  })
  ...&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;UGHHHHHH. Did you think that a Scala wrapper would make code-based interfaces breezy and fun? Sorry to disappoint! This is probably nicer than the equivalent in regular Java Swing, but it&amp;#8217;s still pretty annoying. And boy, wasn&amp;#8217;t it fun adjusting each &lt;code&gt;gridy&lt;/code&gt; value to mock up different arrangements? (It was not fun.) That process should be done with an interface tool (an &amp;#8220;interface builder&amp;#8221;, one might call it) that produces resource files. &lt;a href=&quot;http://www.netbeans.org/features/java/swing.html&quot;&gt;Generating Java code&lt;/a&gt; is not the same and is particularly unhelpful in this circumstance where Java is not the language and the the code is not under any &lt;abbr&gt;IDE&lt;/abbr&gt;&amp;#8217;s obsessive control. No, an interface descriptor to go in &lt;code&gt;data/&lt;/code&gt; along with the fonts and images would be a thousand times better.&lt;/p&gt;

&lt;p&gt;Anywho, this code-based layout is actually decent looking, even on practically abandoned Java platforms:&lt;/p&gt;

&lt;p class=&quot;break&quot;&gt; &lt;img src=&quot;http://technically.us/resources/com.typeturner.Typeturner/image?name=friday-mac&quot; alt=&quot;Friday on Mac OS X&quot; /&gt;&lt;/p&gt;

&lt;p class=&quot;break&quot;&gt; So if you have some hours to kill, yes you can cajole Swing layouts into looking passably native. The problem is not the pixels (although they are not perfect or else &lt;a href=&quot;http://www.randelshofer.ch/quaqua/index.html&quot;&gt;Quaqua&lt;/a&gt; would not exist). The problem is that tweaking layouts is tedious and most programmers won&amp;#8217;t bother with it, even with a good layout tool. And without one, nobody is willing to sit through the two hundred tweak-compile-run cycles that a typically complicated interface will require to get right.&lt;/p&gt;

&lt;p&gt;Don&amp;#8217;t worry though, Friday&amp;#8217;s simple setup screen only required fifteen head-smacking cycles.&lt;/p&gt;
&lt;p class=&quot;break&quot;&gt;&lt;a href=&quot;http://technically.us/downloads/Friday.jar&quot;&gt;&lt;img src=&quot;http://technically.us/resources/com.typeturner.Typeturner/image?name=friday-jar&quot; /&gt;&lt;/a&gt;&lt;br /&gt;
&lt;i&gt;Runnable jar&lt;/i&gt;
&lt;/p&gt;&lt;p class=&quot;break&quot;&gt;&lt;a href=&quot;http://technically.us/downloads/Friday-mac.zip&quot;&gt;&lt;img src=&quot;http://technically.us/resources/com.typeturner.Typeturner/image?name=friday-bundle&quot; /&gt;&lt;/a&gt;&lt;br /&gt;
&lt;i&gt;Mac app-bundle&lt;/i&gt;
&lt;/p&gt;
&lt;p class=&quot;break&quot;&gt; Please download in an orderly fashion.&lt;/p&gt;</content>
		<author>
			<name>Coderspiel</name>
			<uri>http://technically.us/code</uri>
		</author>
		<source>
			<title type="html">Coderspiel (all posts)</title>
			<subtitle type="html">Programming with creative license.</subtitle>
			<link rel="self" href="http://technically.us/resources/com.typeturner.Typeturner/code-rss?q=scala"/>
			<id>http://technically.us/resources/com.typeturner.Typeturner/code-rss?q=scala</id>
			<updated>2008-12-02T17:20:25+00:00</updated>
		</source>
	</entry>

	<entry>
		<title type="html">Javascript's Undeclared versus Undefined</title>
		<link href="http://kevinoncode.blogspot.com/2008/12/javascripts-undeclared-versus-undefined.html"/>
		<id>tag:blogger.com,1999:blog-1937539813134787961.post-3776220157626298757</id>
		<updated>2008-12-02T12:05:15+00:00</updated>
		<content type="html">I learned the hard way that undeclared is different than undefined.  If you try to test the simple way for an undeclared variable, you get an error, which in my environment means an annoying pop-up.&lt;br /&gt;&lt;pre class=&quot;code&quot;&gt;/* var a; */  // undeclared&lt;br /&gt;var b;        // undefined&lt;br /&gt;&lt;br /&gt;// This would cause an 'object undefined' error&lt;br /&gt;/*&lt;br /&gt;if (a) {&lt;br /&gt;  alert(&quot;a is defined&quot;);&lt;br /&gt;}&lt;br /&gt;else {&lt;br /&gt;  alert(&quot;a is undefined&quot;);&lt;br /&gt;}&lt;br /&gt;*/&lt;br /&gt;&lt;br /&gt;if (typeof(a) == &quot;undefined&quot;) {&lt;br /&gt;  // this will be executed&lt;br /&gt;  alert(&quot;a is undeclared or undefined&quot;);&lt;br /&gt;}&lt;br /&gt;else {&lt;br /&gt;  alert(&quot;a is declared and defined&quot;);&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;if (b) {&lt;br /&gt;  alert(&quot;b is defined&quot;);&lt;br /&gt;}&lt;br /&gt;else {&lt;br /&gt;  // this will be executed&lt;br /&gt;  alert(&quot;b is undefined&quot;);&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;if (typeof(b) == &quot;undefined&quot;) {&lt;br /&gt;  // this will be executed&lt;br /&gt;  alert(&quot;b is undeclared or undefined&quot;);&lt;br /&gt;}&lt;br /&gt;else {&lt;br /&gt;  alert(&quot;b is declared and defined&quot;);&lt;br /&gt;}&lt;/pre&gt;</content>
		<author>
			<name>Kevin Albrecht</name>
			<email>noreply@blogger.com</email>
			<uri>http://kevinoncode.blogspot.com/</uri>
		</author>
		<source>
			<title type="html">Kevin on Code</title>
			<subtitle type="html">Object-oriented programmer by day.
Functional programmer by night.</subtitle>
			<link rel="self" href="http://kevinoncode.blogspot.com/feeds/posts/default"/>
			<id>tag:blogger.com,1999:blog-1937539813134787961</id>
			<updated>2008-12-02T20:20:25+00:00</updated>
		</source>
	</entry>

	<entry xml:lang="en">
		<title type="html">Coincidence?</title>
		<link href="http://matt.immute.net/content/coincidence"/>
		<id>http://matt.immute.net/39 at http://matt.immute.net</id>
		<updated>2008-12-02T05:23:26+00:00</updated>
		<content type="html">&lt;p&gt;These two books, long ago separately pre-ordered, arrived from different places on the same day:&lt;br /&gt;
&lt;a href=&quot;http://www.flickr.com/photos/hellige/3075888733/&quot; title=&quot;today's mail by hellige, on Flickr&quot;&gt;&lt;img src=&quot;http://farm4.static.flickr.com/3059/3075888733_5c6264363d.jpg&quot; width=&quot;500&quot; height=&quot;375&quot; alt=&quot;today's mail&quot; /&gt;&lt;/a&gt;&lt;br /&gt;
One of the things keeping me busy lately has been a Haskell reading group, which has mostly amounted to me teaching some people Haskell, using this book as the main text. We've been using the web preprint, and it's exciting to see the real thing!&lt;/p&gt;
&lt;p&gt;For a long time, I've felt that there were lots of decent &quot;first books&quot; on Haskell, but not a single &quot;second book.&quot; This is especially unfortunate, given that the most difficult part for many people of learning Haskell is making the jump from CS101 stuff to the actual state of the art. This book rectifies that. In fact, having used it with beginners, I'm not sure I'd recommend it as the best very first book on Haskell, but that hardly matters. Since a lot of this material has until now had to be painstakingly gleaned from mailing list archives, conference papers, functional pearls, blogs and sometimes IRC, this is a very welcome reference. It's exciting to see a Haskell book that goes beyond the basics.&lt;/p&gt;
&lt;p&gt;I haven't gotten all the way through it yet, but I'd already happily recommend it. And of course it's great to see the first Scala book in print as well. I understand that 2009 will witness a number of unfortunately similarly named titles. Too bad about the names, otherwise it's a great trend. Congratulations to all six authors of these two books!&lt;/p&gt;</content>
		<author>
			<name>Matt Hellige</name>
			<uri>http://matt.immute.net/taxonomy/term/11/0</uri>
		</author>
		<source>
			<title type="html">mh - scala</title>
			<link rel="self" href="http://matt.immute.net/taxonomy/term/11/0/feed"/>
			<id>http://matt.immute.net/taxonomy/term/11/0/feed</id>
			<updated>2008-12-03T07:20:29+00:00</updated>
		</source>
	</entry>

	<entry>
		<title type="html">Guido's thoughts on Scala</title>
		<link href="http://debasishg.blogspot.com/2008/12/guidos-thoughts-on-scala.html"/>
		<id>tag:blogger.com,1999:blog-22587889.post-2490093962475520401</id>
		<updated>2008-12-01T16:04:09+00:00</updated>
		<content type="html">Many people who have reacted to Guido's &lt;a href=&quot;http://neopythonic.blogspot.com/2008/11/scala.html&quot;&gt;gripes with Scala&lt;/a&gt; have bent the post towards a static-typing-is-bad-and-dynamic-typing-is-good syndrome. I think the main point of concern that Guido expresses relates to the complexity of Scala's type system and the many exceptions to the rules for writing idiomatic Scala.&lt;br /&gt;&lt;br /&gt;While it is true that there are quite a few rough edges in Scala's syntax today, none of them look insurmountable and will surely be addressed by the language designers in the versions to come. We need to remember that Scala is still a very much growing language and needs time and community feedback to evolve into one of the mainstream general purpose languages. As Martin has &lt;a href=&quot;http://www.reddit.com/r/programming/comments/7evke/scala/c06heaw&quot;&gt;mentioned&lt;/a&gt; elsewhere, Scala's grammar is no bigger than Java, OCaml or C# and hence the language should not impose a more complex mental model for using the same set of features that the other statically typed languages espouse. &lt;br /&gt;&lt;br /&gt;However, Scala's typesystem is expressive enough to offer succinct solutions to many problems that would look much more obtuse in Java. A better modeling of the Expression Problem is a classic example, which, as this &lt;a href=&quot;http://www.scala-lang.org/docu/files/IC_TECH_REPORT_200433.pdf&quot;&gt;paper&lt;/a&gt;  demonstrates, looks much more verbose, inelegant and non-extensible using Visitors in Java. I have been programming in Scala for sometime now, and I have the feeling that Scala's extremely rich type system can be exploited to implement domain models that encapsulate most of the business rules through declarative type constraints. I have &lt;a href=&quot;http://debasishg.blogspot.com/2008/10/how-scalas-type-system-works-for-your.html&quot;&gt;blogged&lt;/a&gt;  on this very recently and described my experiences of how Scala's type system, specifically, features like abstract types, self type annotations etc., works for you to implement expressive domain models, without writing a single line of runtime type checking code. Less code, more succinct abstractions, and most importantly less tests to write and maintain. After all, everything has a cost, it depends whether you abstract the complexity within the language or within your application.&lt;br /&gt;&lt;br /&gt;Another excellent point that has been &lt;a href=&quot;http://neopythonic.blogspot.com/2008/11/scala.html?showComment=1227302520000#c8817950180348833579&quot;&gt;raised&lt;/a&gt; by David Pollak in one of the comments to Guido's post is that we need to judge complexity of language features separately depending on whether you are a library producer or a library consumer. As a library producer, you need to be aware of many of the aspects of Scala's type system, which may not be that essential as a library consumer. Sometime back, I had &lt;a href=&quot;http://debasishg.blogspot.com/2008/05/designing-internal-dsls-in-scala.html&quot;&gt;demonstrated&lt;/a&gt; an example of an internal DSL design technique in Scala, where, given a sufficiently typed library for financial trading systems, you can write DSLs in Scala of the form .. &lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;span class=&quot;java_keyword&quot;&gt;new&lt;/span&gt;&lt;span class=&quot;java_plain&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;java_type&quot;&gt;Order&lt;/span&gt;&lt;span class=&quot;java_plain&quot;&gt;&amp;nbsp;to&amp;nbsp;buy&lt;/span&gt;&lt;span class=&quot;java_separator&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;java_literal&quot;&gt;100&lt;/span&gt;&lt;span class=&quot;java_plain&quot;&gt;&amp;nbsp;sharesOf&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;java_literal&quot;&gt;&amp;quot;IBM&amp;quot;&lt;/span&gt;&lt;span class=&quot;java_separator&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;java_plain&quot;&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class=&quot;java_plain&quot;&gt;&amp;nbsp;&amp;nbsp;maxUnitPrice&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;java_literal&quot;&gt;300&lt;/span&gt;&lt;span class=&quot;java_plain&quot;&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class=&quot;java_plain&quot;&gt;&amp;nbsp;&amp;nbsp;using&amp;nbsp;premiumPricing&lt;/span&gt;&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;Another great example is the Scala parser combinator library, which hides all nuances of Scala's type system and allows you to design external DSLs. Have a look at this &lt;a href=&quot;http://debasishg.blogspot.com/2008/04/external-dsls-made-easy-with-scala.html&quot;&gt;example&lt;/a&gt; of another financial trading system DSL built using Scala parser combinators ..&lt;br /&gt;&lt;br /&gt;On the whole I think Scala has a compelling appeal to the programming community on the JVM. Statically checked duck typing that Scala offers makes your code look and feel like Ruby and yet offers the safety net of compile time checking. Scala is object oriented, though most of idiomatic Scala is  functional. In a real world application development environment, where statefulness is the way of life, Scala offers a very good compromise with its hybrid model of programming. Model your states using objects, and model your computations using functional Scala.&lt;br /&gt;&lt;br /&gt;Regarding the other concern raised by Guido on the non-uniformity of Scala's syntax, it is indeed true that there are some rough edges to deal with .. like .. () versus {} in for-comprehensions and inconsistent inferring of semi-colons, the number of interpretations that an underscore (_) can have, some subversions in partial function application syntax, syntax for &lt;code&gt;def foo() { .. }&lt;/code&gt;. I guess there are quite a few of them that are currently being debated as possible candidates for change. The good part is that the language experts are &lt;a href=&quot;http://www.nabble.com/Summary%282%29---things-to-drop-tc20665104.html&quot;&gt;working&lt;/a&gt; with Martin to iron these issues out and smoothen out the rough edges, even at the risk of losing some amount of backwards compatibility.</content>
		<author>
			<name>Debasish</name>
			<email>noreply@blogger.com</email>
			<uri>http://debasishg.blogspot.com/</uri>
		</author>
		<source>
			<title type="html">Ruminations of a Programmer</title>
			<subtitle type="html">A programmer's blog - will deal with everything that relates to a programmer. Occasionally, it will contain some humour, some politics and some sport news.</subtitle>
			<link rel="self" href="http://debasishg.blogspot.com/feeds/posts/default?alt=rss"/>
			<id>tag:blogger.com,1999:blog-22587889</id>
			<updated>2008-12-03T18:00:04+00:00</updated>
		</source>
	</entry>

	<entry xml:lang="en">
		<title type="html">Do Air Conditioning geeks exist?</title>
		<link href="http://blog.tmorris.net/do-air-conditioning-geeks-exist/"/>
		<id>http://blog.tmorris.net/?p=459</id>
		<updated>2008-12-01T08:27:29+00:00</updated>
		<content type="html">&lt;p&gt;I work from home now. It rocks &lt;img src=&quot;http://blog.tmorris.net/wp-includes/images/smilies/icon_smile.gif&quot; alt=&quot;:)&quot; class=&quot;wp-smiley&quot; /&gt; I also live in a rental property in &lt;a href=&quot;http://www.bom.gov.au/climate/averages/tables/cw_040223.shtml&quot;&gt;the warm climate of Brisbane, Australia&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;I wish to convert one of the rooms &amp;mdash; westward-facing, 3 metres by 3 metres &amp;mdash; into my office. I currently work in the main living area under a split system A/C and this has some problems that I want to alleviate.&lt;/p&gt;
&lt;p&gt;Below is an image of the only window in this room. It has a single slider 570mm by 1450mm (the pink line) which is fitted with a security screen by pop-rivets. This window faces west and there is drainage outside.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;http://public.tmorris.net/image/misc/bedroomwindow.jpg&quot; alt=&quot;Bedroom Window&quot; /&gt;&lt;/p&gt;
&lt;p&gt;What is an appropriate set up for cooling such a room, given that it is a rental property? I have looked at evaporative coolers and portable air conditioners but have been advised against both given our climate. It also appears somewhat difficult to use a portable A/C given the fixed security screen and the need for an external vent &amp;mdash; can it me reversibly modified somehow? I find no other appropriate option and am a bit of a deadlock. Advice?&lt;/p&gt;</content>
		<author>
			<name>Tony Morris</name>
			<uri>http://blog.tmorris.net</uri>
		</author>
		<source>
			<title type="html">λ Tony’s blog λ</title>
			<subtitle type="html">The weblog of Tony Morris</subtitle>
			<link rel="self" href="http://blog.tmorris.net/feed/"/>
			<id>http://blog.tmorris.net/feed/</id>
			<updated>2008-12-03T07:40:30+00:00</updated>
		</source>
	</entry>

	<entry xml:lang="en">
		<title type="html">Introduction to Automated Proof Verification with SASyLF</title>
		<link href="http://www.codecommit.com/blog/scala/introduction-to-automated-proof-verification-with-sasylf"/>
		<id>http://www.codecommit.com/blog/scala/introduction-to-automated-proof-verification-with-sasylf</id>
		<updated>2008-12-01T08:00:00+00:00</updated>
		<content type="html">&lt;p&gt;Doesn&amp;#8217;t that title just get the blood pumping?&amp;nbsp; Proof verification has a reputation for being an inordinately academic subject.&amp;nbsp; In fact, even within scholarly (otherwise known as &amp;#8220;&lt;em&gt;unrealistically intelligent&lt;/em&gt;&amp;#8220;) circles, the automated verification of proofs is known mainly as a complex, ugly and difficult task often not worth the effort.&amp;nbsp; This is a shame really, because rigorous proofs are at the very core of both mathematics and computer science.&amp;nbsp; We are nothing without logic (paraphrased contrapositive from Descartes).&amp;nbsp; Believe it or not, understanding basic proof techniques will be of tremendous aid to your cognitive process, even when working on slightly less ethereal problems such as how to get the freakin&amp;#8217; login page to work properly.&lt;/p&gt;
&lt;p&gt;Well, if you made it all the way to the second paragraph, then you either believe me when I say that this is legitimately useful (and cool!) stuff, or you&amp;#8217;re just plain bored.&amp;nbsp; Either way, read on as we commence our exciting journey into the land of rigorous proofs!&lt;/p&gt;
&lt;h3&gt;SASyLF Crash Course&lt;/h3&gt;
&lt;p&gt;If you&amp;#8217;re at all familiar with the somewhat&amp;#45;specialized field of proof verification, you probably know that &lt;a href=&quot;http://www.sasylf.org&quot;&gt;SASyLF&lt;/a&gt; (pronounced &amp;#8220;sassy elf&amp;#8221;) is &lt;em&gt;not&lt;/em&gt; the most widely used tool for the job.&amp;nbsp; In fact, it may very well be the least well&amp;#45;known.&amp;nbsp; More commonly, proofs that require automatic verification are written in &lt;a href=&quot;http://twelf.plparty.org/wiki/Main_Page&quot;&gt;Twelf&lt;/a&gt; or &lt;a href=&quot;http://coq.inria.fr/&quot;&gt;Coq&lt;/a&gt;.&amp;nbsp; Both of these are fine tools and capable of a lot more than SASyLF, but they can also be extremely difficult to use.&amp;nbsp; One of the primary motivations behind SASyLF was to produce a tool which was easier to learn, had a higher level syntax (easier to read) and which gave more helpful error messages than Twelf.&amp;nbsp; The main idea behind these convolutions was to produce a tool which was more suitable for use in the classroom.&lt;/p&gt;
&lt;p&gt;The main design decision which sets SASyLF apart from Twelf is the way in which proofs are expressed.&amp;nbsp; As I understand it, Twelf exploits &lt;a href=&quot;http://en.wikipedia.org/wiki/Curry-Howard_correspondence&quot;&gt;Curry&amp;#45;Howard correspondence&lt;/a&gt; to represent proofs implicitly in the types of a functional program (&lt;strong&gt;disclaimer:&lt;/strong&gt; I&amp;#8217;ve never used Twelf, this is just coming from what little I have read about it).&amp;nbsp; While this can be very powerful, it&amp;#8217;s not the most intuitive way to think about a proof.&amp;nbsp; Eschewing this approach, SASyLF expresses proofs using &lt;em&gt;unification&lt;/em&gt; (very similar to Prolog) and defines inference rules explicitly in a natural&amp;#45;language style.&lt;/p&gt;
&lt;p&gt;There are three main components to a SASyLF proof:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Syntax&lt;/li&gt;
&lt;li&gt;Judgments&lt;/li&gt;
&lt;li&gt;Theorems/Lemmas&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Intuitively enough, the syntax section is where we express the grammar for the language used throughout our proof.&amp;nbsp; This grammar is expressed very naturally using BNF, just as if we were defining the language mathematically for a hand&amp;#45;written proof.&amp;nbsp; Left&amp;#45;recursion is allowed, as is right&amp;#45;recursion, arbitrary symbols, ambiguity and so on.&amp;nbsp; SASyLF&amp;#8217;s parser is mind bogglingly powerful, capable of chewing threw just about any syntax you throw at it.&amp;nbsp; The main restriction is that you cannot use parentheses, square brackets (&lt;code&gt;[]&lt;/code&gt;), pipes (&lt;code&gt;|&lt;/code&gt;) or periods (&lt;code&gt;.&lt;/code&gt;) in your syntax.&amp;nbsp; The pure&amp;#45;untyped lambda calculus defined in SASyLF would look something like this:&lt;/p&gt;
&lt;div class=&quot;wp_syntax&quot;&gt;
&lt;table&gt;
&lt;tr&gt;
&lt;td class=&quot;line_numbers&quot;&gt;&lt;/td&gt;
&lt;td class=&quot;code&quot;&gt;
&lt;pre class=&quot;sasylf&quot;&gt;&lt;span&gt;t ::=&lt;span&gt; &lt;/span&gt;&lt;span&gt;fn&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;x&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;=&lt;/span&gt;&lt;span&gt;&amp;gt;&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;t&lt;/span&gt;&lt;span&gt;[&lt;/span&gt;&lt;span&gt;x&lt;/span&gt;&lt;span&gt;]&lt;/span&gt;
&lt;span&gt; &lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;|&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;t&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;t&lt;/span&gt;
&lt;span&gt; &lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;|&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;x&lt;/span&gt;
&lt;/span&gt;&lt;/pre&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;
&lt;/div&gt;
&lt;p&gt;I said we couldn&amp;#8217;t use brackets, but that&amp;#8217;s only because SASyLF assigns some special magic to these operators.&amp;nbsp; In a nutshell, they allow the above definition of lambda calculus to ignore all of the issues associated with variable name freshness and context.&amp;nbsp; For simplicity&amp;#8217;s sake, that&amp;#8217;s about as far as I&amp;#8217;m going to go into these mysterious little thingies.&lt;/p&gt;
&lt;p&gt;The judgments section is where we define our inference rules.&amp;nbsp; Just as if we were defining these rules by hand, the syntax has the conditionals above a line of hyphens with the conclusion below.&amp;nbsp; The label for the rule goes to the right of the &amp;#8220;line&amp;#8221;.&amp;nbsp; What could be more natural?&lt;/p&gt;
&lt;div class=&quot;wp_syntax&quot;&gt;
&lt;table&gt;
&lt;tr&gt;
&lt;td class=&quot;line_numbers&quot;&gt;&lt;/td&gt;
&lt;td class=&quot;code&quot;&gt;
&lt;pre class=&quot;sasylf&quot;&gt;&lt;span&gt;&lt;span&gt;judgment&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;eval&lt;/span&gt;&lt;span&gt;:&lt;/span&gt; t &amp;#45;&amp;gt; t

t1 &amp;#45;&amp;gt; t1&amp;#8242;
&lt;span&gt;&amp;#45;&amp;#45;&amp;#45;&amp;#45;&amp;#45;&amp;#45;&amp;#45;&amp;#45;&amp;#45;&amp;#45;&amp;#45;&amp;#45;&amp;#45;&amp;#45;&amp;#45;&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;E&amp;#45;Beta1&lt;/span&gt;
t1 t2 &amp;#45;&amp;gt; t1&amp;#8242; t2
&lt;/span&gt;&lt;/pre&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;
&lt;/div&gt;
&lt;p&gt;The &lt;code&gt;judgment&lt;/code&gt; syntax is what defines the syntax for the &lt;code&gt;&amp;#45;&amp;gt;&lt;/code&gt; &amp;#8220;operator&amp;#8221;.&amp;nbsp; Once SASyLF sees this, it knows that we may define rules of the form &lt;code&gt;t &amp;#45;&amp;gt; t&lt;/code&gt;, where &lt;code&gt;t&lt;/code&gt; is defined by the syntax section.&amp;nbsp; Further on down, SASyLF sees our &lt;code&gt;E&amp;#45;Beta1&lt;/code&gt; rule.&amp;nbsp; Each of the tokens within this rule (aside from &lt;code&gt;&amp;#45;&amp;gt;&lt;/code&gt;) begins with &amp;#8220;&lt;code&gt;t&lt;/code&gt;&amp;#8220;.&amp;nbsp; From this, SASyLF is able to infer that we mean &amp;#8220;a term as defined previously&amp;#8221;.&amp;nbsp; Thus, this rule is syntactically valid according to our evaluation judgment and the syntax given above.&lt;/p&gt;
&lt;p&gt;Of course, theorems are where you will find the real meat of any proof (I&amp;#8217;m using the word &amp;#8220;proof&amp;#8221; very loosely to mean the collection of proven theorems and lemmas which indicates some fact(s) about a language).&amp;nbsp; SASyLF wouldn&amp;#8217;t be a very complete proof verification system without support for some form of proving.&amp;nbsp; Once again, the syntax is extremely natural language, almost to the point of being overly&amp;#45;verbose.&amp;nbsp; A simple theorem given the rules above plus a little would be to show that values cannot evaluate:&lt;/p&gt;
&lt;div class=&quot;wp_syntax&quot;&gt;
&lt;table&gt;
&lt;tr&gt;
&lt;td class=&quot;line_numbers&quot;&gt;&lt;/td&gt;
&lt;td class=&quot;code&quot;&gt;
&lt;pre class=&quot;sasylf&quot;&gt;&lt;span&gt;&lt;span&gt;theorem&lt;/span&gt; &lt;span&gt;eval&amp;#45;value&amp;#45;implies&amp;#45;contradiction:&lt;/span&gt;
    &lt;span&gt;forall&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;e:&lt;/span&gt; t &amp;#45;&amp;gt; t&amp;#8217;
    &lt;span&gt;forall&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;v:&lt;/span&gt; t value
    &lt;span&gt;exists&lt;/span&gt; contradiction &lt;span&gt;.&lt;/span&gt;

&lt;span&gt; &lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;_:&lt;/span&gt;&lt;span&gt; &lt;/span&gt;contradiction &lt;span&gt;by&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;unproved&lt;/span&gt;
&lt;span&gt;end theorem&lt;/span&gt;
&lt;/span&gt;&lt;/pre&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;
&lt;/div&gt;
&lt;p&gt;Note that &lt;code&gt;contradiction&lt;/code&gt; is not more SASyLF magic.&amp;nbsp; We can actually define what it means to have a contradiction by adding the following lines to our judgment section:&lt;/p&gt;
&lt;div class=&quot;wp_syntax&quot;&gt;
&lt;table&gt;
&lt;tr&gt;
&lt;td class=&quot;line_numbers&quot;&gt;&lt;/td&gt;
&lt;td class=&quot;code&quot;&gt;
&lt;pre class=&quot;sasylf&quot;&gt;&lt;span&gt;&lt;span&gt;judgment&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;absurd&lt;/span&gt;&lt;span&gt;:&lt;/span&gt; contradiction
&lt;/span&gt;&lt;/pre&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;
&lt;/div&gt;
&lt;p&gt;In other words, we can have a contradiction, but there are no rules which allow us to get it.&amp;nbsp; In fact, the only way to have a contradiction is to somehow get SASyLF to the point where it sees that there are no cases which satisfy some set of proven facts (given the &lt;code&gt;forall&lt;/code&gt; assumptions).&amp;nbsp; If SASyLF cannot find any cases to satisfy some rules, it allows us to derive anything at all, including judgments which have no corresponding rules.&lt;/p&gt;
&lt;p&gt;Readers who have yet to fall asleep will notice that I cleverly elided a portion of the &amp;#8220;&lt;code&gt;theorem&lt;/code&gt;&amp;#8221; code snippet.&amp;nbsp; That&amp;#8217;s because there wasn&amp;#8217;t really a way to prove that contradiction given the drastically abbreviated rules given in earlier samples.&amp;nbsp; Instead of proving anything, I used a special SASyLF justification, &lt;code&gt;unproved&lt;/code&gt;, which allows the derivation of any fact given no input (very useful for testing incomplete proofs).&amp;nbsp; Lambda calculus isn&amp;#8217;t much more complicated than what I showed, but it does require more than just an application context rule in its evaluation semantics.&amp;nbsp; In order to get a taste for SASyLF&amp;#8217;s proof syntax, we&amp;#8217;re going to need to look at a much simpler language.&lt;/p&gt;
&lt;h3&gt;Case Study: Integer Comparison&lt;/h3&gt;
&lt;p&gt;For this case study, we&amp;#8217;re going to be working with simple counting numbers which start with &lt;code&gt;0&lt;/code&gt; and then proceed upwards, each value expressed as the successor of its previous value.&amp;nbsp; Thus, the logical number 3 would be &lt;code&gt;s s s 0&lt;/code&gt;.&amp;nbsp; Not a very useful language in the real world, but much easier to deal with in the field of proof verification.&amp;nbsp; The syntax for our natural numbers looks like this:&lt;/p&gt;
&lt;div class=&quot;wp_syntax&quot;&gt;
&lt;table&gt;
&lt;tr&gt;
&lt;td class=&quot;line_numbers&quot;&gt;&lt;/td&gt;
&lt;td class=&quot;code&quot;&gt;
&lt;pre class=&quot;sasylf&quot;&gt;&lt;span&gt;n ::=&lt;span&gt; &lt;/span&gt;&lt;span&gt;0&lt;/span&gt;
&lt;span&gt; &lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;|&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;s&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;n&lt;/span&gt;
&lt;/span&gt;&lt;/pre&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;
&lt;/div&gt;
&lt;p&gt;With this humble definition for &lt;code&gt;n&lt;/code&gt;, we can go on to define the mathematical greater&amp;#45;than comparison using two rules under a single judgment:&lt;/p&gt;
&lt;div class=&quot;wp_syntax&quot;&gt;
&lt;table&gt;
&lt;tr&gt;
&lt;td class=&quot;line_numbers&quot;&gt;&lt;/td&gt;
&lt;td class=&quot;code&quot;&gt;
&lt;pre class=&quot;sasylf&quot;&gt;&lt;span&gt;&lt;span&gt;judgment&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;gt&lt;/span&gt;&lt;span&gt;:&lt;/span&gt; n &amp;gt; n

&lt;span&gt;&amp;#45;&amp;#45;&amp;#45;&amp;#45;&amp;#45;&amp;#45;&amp;#45;&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;gt&amp;#45;one&lt;/span&gt;
s n &amp;gt; n

n1 &amp;gt; n2
&lt;span&gt;&amp;#45;&amp;#45;&amp;#45;&amp;#45;&amp;#45;&amp;#45;&amp;#45;&amp;#45;&amp;#45;&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;gt&amp;#45;more&lt;/span&gt;
s n1 &amp;gt; n2
&lt;/span&gt;&lt;/pre&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;
&lt;/div&gt;
&lt;p&gt;Believe it or not, this is all we need to do in terms of definition.&amp;nbsp; The first rule says that the successor of any number is greater than that same number (3 &amp;gt; 2).&amp;nbsp; The second rule states that if we already have two numbers, one greater than the other (12 &amp;gt; 4), then the successor of the greater number will still be greater than the lesser (13 &amp;gt; 4).&amp;nbsp; All very intuitive, but the real question is whether or not we can prove anything with these definitions.&lt;/p&gt;
&lt;h4&gt;An Easy Lemma&lt;/h4&gt;
&lt;p&gt;For openers, we can try something reasonably simple: prove that all non&amp;#45;zero numbers are greater than zero.&amp;nbsp; This is such a simple proof that we won&amp;#8217;t even bother calling it a theorem, we will give it the lesser rank of &amp;#8220;lemma&amp;#8221;:&lt;/p&gt;
&lt;div class=&quot;wp_syntax&quot;&gt;
&lt;table&gt;
&lt;tr&gt;
&lt;td class=&quot;line_numbers&quot;&gt;&lt;/td&gt;
&lt;td class=&quot;code&quot;&gt;
&lt;pre class=&quot;sasylf&quot;&gt;&lt;span&gt;&lt;span&gt;lemma&lt;/span&gt; &lt;span&gt;all&amp;#45;gt&amp;#45;zero:&lt;/span&gt;
    &lt;span&gt;forall&lt;/span&gt;&lt;span&gt; &lt;/span&gt;n
    &lt;span&gt;exists&lt;/span&gt; s n &amp;gt; 0 &lt;span&gt;.&lt;/span&gt;

&lt;span&gt;    &lt;/span&gt;&lt;span&gt;_:&lt;/span&gt;&lt;span&gt; &lt;/span&gt;s n &amp;gt; 0 &lt;span&gt;by&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;induction&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;on &lt;/span&gt;&lt;span&gt;n:&lt;/span&gt;
        &lt;span&gt;case&lt;/span&gt; 0 &lt;span&gt;is&lt;/span&gt;
&lt;span&gt;    &lt;/span&gt;&lt;span&gt;    &lt;/span&gt;&lt;span&gt;    &lt;/span&gt;&lt;span&gt;_:&lt;/span&gt;&lt;span&gt; &lt;/span&gt;s 0 &amp;gt; 0 &lt;span&gt;by&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;rule&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;gt&amp;#45;one&lt;/span&gt;
        &lt;span&gt;end case&lt;/span&gt;

        &lt;span&gt;case&lt;/span&gt; s n1 &lt;span&gt;is&lt;/span&gt;
&lt;span&gt;    &lt;/span&gt;&lt;span&gt;    &lt;/span&gt;&lt;span&gt;    &lt;/span&gt;&lt;span&gt;g:&lt;/span&gt;&lt;span&gt; &lt;/span&gt;s n1 &amp;gt; 0 &lt;span&gt;by&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;induction hypothesis&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;on &lt;/span&gt;&lt;span&gt;n1&lt;/span&gt;
&lt;span&gt;    &lt;/span&gt;&lt;span&gt;    &lt;/span&gt;&lt;span&gt;    &lt;/span&gt;&lt;span&gt;_:&lt;/span&gt;&lt;span&gt; &lt;/span&gt;s s n1 &amp;gt; 0 &lt;span&gt;by&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;rule&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;gt&amp;#45;more&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;on &lt;/span&gt;&lt;span&gt;g&lt;/span&gt;
        &lt;span&gt;end case&lt;/span&gt;
    &lt;span&gt;end induction&lt;/span&gt;
&lt;span&gt;end lemma&lt;/span&gt;
&lt;/span&gt;&lt;/pre&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;
&lt;/div&gt;
&lt;p&gt;In order to prove anything about &lt;code&gt;n&lt;/code&gt;, we first need to &amp;#8220;pull it apart&amp;#8221; and find out what it&amp;#8217;s made of.&amp;nbsp; To do that, we&amp;#8217;re going to use &lt;code&gt;induction&lt;/code&gt;.&amp;nbsp; We could also use &lt;code&gt;case analysis&lt;/code&gt;, but that would only work if our proof didn&amp;#8217;t require &amp;#8220;recursion&amp;#8221; (we&amp;#8217;ll get to this in a minute).&amp;nbsp; There are two cases as given by the syntax for &lt;code&gt;n&lt;/code&gt;: when &lt;code&gt;n&lt;/code&gt; is &amp;#8220;&lt;code&gt;0&lt;/code&gt;&amp;#8220;, and when &lt;code&gt;n&lt;/code&gt; is &amp;#8220;&lt;code&gt;s n1&lt;/code&gt;&amp;#8220;, where &lt;code&gt;n1&lt;/code&gt; is some other number.&amp;nbsp; We must prove that &lt;code&gt;s n &amp;gt; 0&lt;/code&gt; for both of these cases individually, otherwise our proof is not valid.&lt;/p&gt;
&lt;p&gt;The first case is easy.&amp;nbsp; When &lt;code&gt;n&lt;/code&gt; is 0, the proof is trivial using the rule &lt;code&gt;gt&amp;#45;one&lt;/code&gt;.&amp;nbsp; Notice that within this case we are no longer proving &lt;code&gt;s n &amp;gt; 0&lt;/code&gt;, but rather &lt;code&gt;s 0 &amp;gt; 0&lt;/code&gt;.&amp;nbsp; This is the huge win brought by SASyLF&amp;#8217;s unification: &lt;code&gt;n&lt;/code&gt; &lt;em&gt;is&lt;/em&gt; &amp;#8220;&lt;code&gt;0&lt;/code&gt;&amp;#8221; within this case.&amp;nbsp; Anything we already know about &lt;code&gt;n&lt;/code&gt;, we also know about &lt;code&gt;0&lt;/code&gt;.&amp;nbsp; When we apply the rule &lt;code&gt;gt&amp;#45;one&lt;/code&gt;, SASyLF sees that we are attempting to prove &lt;code&gt;s n &amp;gt; n&lt;/code&gt; where &lt;code&gt;n&lt;/code&gt; is &amp;#8220;&lt;code&gt;0&lt;/code&gt;&amp;#8220;.&amp;nbsp; This is valid by the rule, so the verification passes.&lt;/p&gt;
&lt;p&gt;The second case is where things get interesting.&amp;nbsp; We have that &lt;code&gt;n&lt;/code&gt; is actually &lt;code&gt;s n1&lt;/code&gt;, but that doesn&amp;#8217;t really get us too much closer to proving &lt;code&gt;s s n1 &amp;gt; 0&lt;/code&gt; (remember, unification).&amp;nbsp; Fortunately, we &lt;em&gt;can&lt;/em&gt; prove that &lt;code&gt;s n1 &amp;gt; 0&lt;/code&gt; because we&amp;#8217;re writing a lemma at this very moment which prove that.&amp;nbsp; This is like writing a function to sum all the values in a list: when the list is empty, the result is trivial; but when the list has contents, we must take the head and then add it to the sum of the tail as computed by&amp;#8230;ourself.&amp;nbsp; Induction is literally just recursion in logic.&amp;nbsp; Interestingly enough, SASyLF is smart enough to look at all of the inductive cases in your proof and verify that they are valid.&amp;nbsp; This is sort&amp;#45;of the equivalent of a compiler looking at your code and telling you whether or not it will lead to an infinite loop.&lt;/p&gt;
&lt;p&gt;To get that &lt;code&gt;s n1 &amp;gt; 0&lt;/code&gt;, we use the induction hypothesis, passing &lt;code&gt;n1&lt;/code&gt; as the &amp;#8220;parameter&amp;#8221;.&amp;nbsp; However, we&amp;#8217;re not quite done yet.&amp;nbsp; We need to prove that &lt;code&gt;s s n1 &amp;gt; 0&lt;/code&gt; in order to unify with our original target (&lt;code&gt;s n &amp;gt; 0&lt;/code&gt;).&amp;nbsp; Fortunately, we already have a rule that allows us to prove the successor of a number retains its greater&amp;#45;than status: &lt;code&gt;gt&amp;#45;more&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;However, &lt;code&gt;gt&amp;#45;more&lt;/code&gt; has a condition in our definition.&amp;nbsp; It requires that we already have some fact &lt;code&gt;n1 &amp;gt; n2&lt;/code&gt; in order to obtain &lt;code&gt;s n1 &amp;gt; n2&lt;/code&gt;.&amp;nbsp; In our case, we already have this fact (&lt;code&gt;s n1 &amp;gt; 0&lt;/code&gt;), but we need to &amp;#8220;pass&amp;#8221; it to the rule.&amp;nbsp; SASyLF allows us to do this by giving our facts labels.&amp;nbsp; In this case, we have labeled the &lt;code&gt;s n1 &amp;gt; 0&lt;/code&gt; fact as &amp;#8220;&lt;code&gt;g&lt;/code&gt;&amp;#8220;.&amp;nbsp; We take this fact, pack it up and send it to &lt;code&gt;gt&amp;#45;more&lt;/code&gt; and it gives us back our final goal.&lt;/p&gt;
&lt;h4&gt;A Slightly Harder Theorem&lt;/h4&gt;
&lt;p&gt;A slightly more difficult task would be to prove that the successors of two numbers preserves their greater&amp;#45;than relationship.&amp;nbsp; Thus, if we know that 4 &amp;gt; 3, we can prove that 5 &amp;gt; 4.&amp;nbsp; More formally:&lt;/p&gt;
&lt;div class=&quot;wp_syntax&quot;&gt;
&lt;table&gt;
&lt;tr&gt;
&lt;td class=&quot;line_numbers&quot;&gt;&lt;/td&gt;
&lt;td class=&quot;code&quot;&gt;
&lt;pre class=&quot;sasylf&quot;&gt;&lt;span&gt;&lt;span&gt;theorem&lt;/span&gt; &lt;span&gt;gt&amp;#45;implies&amp;#45;gt&amp;#45;succ:&lt;/span&gt;
    &lt;span&gt;forall&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;g:&lt;/span&gt; n1 &amp;gt; n2
    &lt;span&gt;exists&lt;/span&gt; s n1 &amp;gt; s n2 &lt;span&gt;.&lt;/span&gt;

&lt;span&gt;    &lt;/span&gt;&lt;span&gt;_:&lt;/span&gt;&lt;span&gt; &lt;/span&gt;s n1 &amp;gt; s n2 &lt;span&gt;by&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;unproved&lt;/span&gt;
&lt;span&gt;end theorem&lt;/span&gt;
&lt;/span&gt;&lt;/pre&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;
&lt;/div&gt;
&lt;p&gt;At first glance, this looks impossible since we don&amp;#8217;t really have a rule dealing with &lt;code&gt;s n&lt;/code&gt; on the right&amp;#45;hand side of the &lt;code&gt;&amp;gt;&lt;/code&gt;&amp;#45;sign.&amp;nbsp; We can try to prove this one step at a time to see whether or not this intuition is correct.&lt;/p&gt;
&lt;p&gt;Almost any lemma of interest is going to require induction, so immediately we jump to inducting on the only fact we have available: &lt;code&gt;g&lt;/code&gt;.&amp;nbsp; Note that this is different from what we had in the earlier example.&amp;nbsp; Instead of getting the different syntactic cases, we&amp;#8217;re looking at the the rules which would have allowed the input to be constructed.&amp;nbsp; After all, whoever &amp;#8220;called&amp;#8221; our theorem will have needed to somehow prove that &lt;code&gt;n1 &amp;gt; n2&lt;/code&gt;, it would be helpful to know what facts they used to do that.&amp;nbsp; SASyLF allows this using the &lt;code&gt;case rule&lt;/code&gt; syntax.&amp;nbsp; We start with the easy base case:&lt;/p&gt;
&lt;div class=&quot;wp_syntax&quot;&gt;
&lt;table&gt;
&lt;tr&gt;
&lt;td class=&quot;line_numbers&quot;&gt;&lt;/td&gt;
&lt;td class=&quot;code&quot;&gt;
&lt;pre class=&quot;sasylf&quot;&gt;&lt;span&gt;&lt;span&gt;_:&lt;/span&gt;&lt;span&gt; &lt;/span&gt;s n1 &amp;gt; s n2 &lt;span&gt;by&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;induction&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;on &lt;/span&gt;&lt;span&gt;g:&lt;/span&gt;
    &lt;span&gt;case rule&lt;/span&gt;
&lt;span&gt;    &lt;/span&gt;&lt;span&gt;    &lt;/span&gt;&lt;span&gt;&amp;#45;&amp;#45;&amp;#45;&amp;#45;&amp;#45;&amp;#45;&amp;#45;&amp;#45;&amp;#45;&amp;#45;&amp;#45;&amp;#45;&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;gt&amp;#45;one&lt;/span&gt;
&lt;span&gt;    &lt;/span&gt;&lt;span&gt;    &lt;/span&gt;&lt;span&gt;_:&lt;/span&gt;&lt;span&gt; &lt;/span&gt;s n2 &amp;gt; n2
    &lt;span&gt;is&lt;/span&gt;
&lt;span&gt;    &lt;/span&gt;&lt;span&gt;    &lt;/span&gt;&lt;span&gt;_:&lt;/span&gt;&lt;span&gt; &lt;/span&gt;s s n2 &amp;gt; s n2 &lt;span&gt;by&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;rule&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;gt&amp;#45;one&lt;/span&gt;
    &lt;span&gt;end case&lt;/span&gt;
&lt;span&gt;end induction&lt;/span&gt;
&lt;/span&gt;&lt;/pre&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;
&lt;/div&gt;
&lt;p&gt;In this case, the term &lt;code&gt;_: s n2 &amp;gt; n2&lt;/code&gt; is unified with &lt;code&gt;n1 &amp;gt; n2&lt;/code&gt;.&amp;nbsp; Thus, &lt;code&gt;n1&lt;/code&gt; is actually &amp;#8220;&lt;code&gt;s n2&lt;/code&gt;&amp;#8220;.&amp;nbsp; This means that by unification, we are actually trying to prove &lt;code&gt;s s n2 &gt; s n2&lt;/code&gt;.&amp;nbsp; Fortunately, we have a rule for that.&amp;nbsp; If we let &amp;#8220;&lt;code&gt;n&lt;/code&gt;&amp;#8221; be &amp;#8220;&lt;code&gt;s n2&lt;/code&gt;&amp;#8220;, we can easily apply the rule &lt;code&gt;gt&amp;#45;one&lt;/code&gt; to produce the desired result.&lt;/p&gt;
&lt;p&gt;The second case is a bit trickier.&amp;nbsp; We start out by defining the case rule according to the inference rules given in the judgment section.&amp;nbsp; The only case left is &lt;code&gt;gt&amp;#45;more&lt;/code&gt;, so we mindlessly copy/paste and correct the variables to suit our needs:&lt;/p&gt;
&lt;div class=&quot;wp_syntax&quot;&gt;
&lt;table&gt;
&lt;tr&gt;
&lt;td class=&quot;line_numbers&quot;&gt;&lt;/td&gt;
&lt;td class=&quot;code&quot;&gt;
&lt;pre class=&quot;sasylf&quot;&gt;&lt;span&gt;&lt;span&gt;case rule&lt;/span&gt;
&lt;span&gt;    &lt;/span&gt;&lt;span&gt;g1:&lt;/span&gt;&lt;span&gt; &lt;/span&gt;n11 &amp;gt; n2
&lt;span&gt;    &lt;/span&gt;&lt;span&gt;&amp;#45;&amp;#45;&amp;#45;&amp;#45;&amp;#45;&amp;#45;&amp;#45;&amp;#45;&amp;#45;&amp;#45;&amp;#45;&amp;#45;&amp;#45;&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;gt&amp;#45;more&lt;/span&gt;
&lt;span&gt;    &lt;/span&gt;&lt;span&gt;_:&lt;/span&gt;&lt;span&gt; &lt;/span&gt;s n11 &amp;gt; n2
&lt;span&gt;is&lt;/span&gt;
&lt;span&gt;    &lt;/span&gt;&lt;span&gt;_:&lt;/span&gt;&lt;span&gt; &lt;/span&gt;s s n11 &amp;gt; s n2 &lt;span&gt;by&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;unproved&lt;/span&gt;
&lt;span&gt;end case&lt;/span&gt;
&lt;/span&gt;&lt;/pre&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;
&lt;/div&gt;
&lt;p&gt;In this case, &lt;code&gt;n1&lt;/code&gt; actually unifies with &amp;#8220;&lt;code&gt;s n11&lt;/code&gt;&amp;#8220;.&amp;nbsp; This is probably the most annoying aspect of SASyLF: all of the syntax is determined by token prefix, so &lt;em&gt;every&lt;/em&gt; number has to start with &lt;code&gt;n&lt;/code&gt;, occasionally making proofs a little difficult to follow.&lt;/p&gt;
&lt;p&gt;At this point, we need to derive &lt;code&gt;s s n11 &amp;gt; s n2&lt;/code&gt;.&amp;nbsp; Since the left and right side of the &lt;code&gt;&amp;gt;&lt;/code&gt; &amp;#8220;operator&amp;#8221; do not share a common sub&amp;#45;term, the only rule which could possibly help us is &lt;code&gt;gt&amp;#45;more&lt;/code&gt;.&amp;nbsp; In order to apply this rule, we will somehow need to derive &lt;code&gt;s n11 &amp;gt; s n2&lt;/code&gt; (remember, &lt;code&gt;gt&amp;#45;more&lt;/code&gt; takes a known greater&amp;#45;than relationship and then tells us something about how the left&amp;#45;successor relates to the right).&amp;nbsp; We can reflect this &amp;#8220;bottom&amp;#45;up&amp;#8221; step towards a proof in the following way:&lt;/p&gt;
&lt;div class=&quot;wp_syntax&quot;&gt;
&lt;table&gt;
&lt;tr&gt;
&lt;td class=&quot;line_numbers&quot;&gt;&lt;/td&gt;
&lt;td class=&quot;code&quot;&gt;
&lt;pre class=&quot;sasylf&quot;&gt;&lt;span&gt;&lt;span&gt;case rule&lt;/span&gt;
&lt;span&gt;    &lt;/span&gt;&lt;span&gt;g1:&lt;/span&gt;&lt;span&gt; &lt;/span&gt;n11 &amp;gt; n2
&lt;span&gt;    &lt;/span&gt;&lt;span&gt;&amp;#45;&amp;#45;&amp;#45;&amp;#45;&amp;#45;&amp;#45;&amp;#45;&amp;#45;&amp;#45;&amp;#45;&amp;#45;&amp;#45;&amp;#45;&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;gt&amp;#45;more&lt;/span&gt;
&lt;span&gt;    &lt;/span&gt;&lt;span&gt;_:&lt;/span&gt;&lt;span&gt; &lt;/span&gt;s n11 &amp;gt; n2
&lt;span&gt;is&lt;/span&gt;
&lt;span&gt;    &lt;/span&gt;&lt;span&gt;g:&lt;/span&gt;&lt;span&gt; &lt;/span&gt;s n11 &amp;gt; s n2 &lt;span&gt;by&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;unproved&lt;/span&gt;
&lt;span&gt;    &lt;/span&gt;&lt;span&gt;_:&lt;/span&gt;&lt;span&gt; &lt;/span&gt;s s n11 &amp;gt; s n2 &lt;span&gt;by&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;rule&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;gt&amp;#45;more&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;on &lt;/span&gt;&lt;span&gt;g&lt;/span&gt;
&lt;span&gt;end case&lt;/span&gt;
&lt;/span&gt;&lt;/pre&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;
&lt;/div&gt;
&lt;p&gt;At this point, SASyLF will warn us about the &lt;code&gt;unproved&lt;/code&gt;, but it will happily pass the rest of our theorem.&amp;nbsp; This technique for proof development is extremely handy in more complicated theorems.&amp;nbsp; The ability to find out whether or not your logic is sound even before it is complete can be very reassuring (in this way you can avoid chasing entirely down the wrong logical path).&lt;/p&gt;
&lt;p&gt;In order to make this whole thing work, we need to somehow prove &lt;code&gt;s n11 &amp;gt; s n2&lt;/code&gt;.&amp;nbsp; Fortunately, we just so happen to be working on a theorem which could prove this if we could supply &lt;code&gt;n11 &amp;gt; n2&lt;/code&gt;.&amp;nbsp; This fact is conveniently available with the label of &amp;#8220;&lt;code&gt;g1&lt;/code&gt;&amp;#8220;.&amp;nbsp; We feed this into the &lt;code&gt;induction hypothesis&lt;/code&gt; to achieve our goal.&amp;nbsp; The final theorem looks like this:&lt;/p&gt;
&lt;div class=&quot;wp_syntax&quot;&gt;
&lt;table&gt;
&lt;tr&gt;
&lt;td class=&quot;line_numbers&quot;&gt;&lt;/td&gt;
&lt;td class=&quot;code&quot;&gt;
&lt;pre class=&quot;sasylf&quot;&gt;&lt;span&gt;&lt;span&gt;theorem&lt;/span&gt; &lt;span&gt;gt&amp;#45;implies&amp;#45;gt&amp;#45;succ:&lt;/span&gt;
    &lt;span&gt;forall&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;g:&lt;/span&gt; n1 &amp;gt; n2
    &lt;span&gt;exists&lt;/span&gt; s n1 &amp;gt; s n2 &lt;span&gt;.&lt;/span&gt;

&lt;span&gt;    &lt;/span&gt;&lt;span&gt;_:&lt;/span&gt;&lt;span&gt; &lt;/span&gt;s n1 &amp;gt; s n2 &lt;span&gt;by&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;induction&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;on &lt;/span&gt;&lt;span&gt;g:&lt;/span&gt;
        &lt;span&gt;case rule&lt;/span&gt;
&lt;span&gt;    &lt;/span&gt;&lt;span&gt;    &lt;/span&gt;&lt;span&gt;    &lt;/span&gt;&lt;span&gt;&amp;#45;&amp;#45;&amp;#45;&amp;#45;&amp;#45;&amp;#45;&amp;#45;&amp;#45;&amp;#45;&amp;#45;&amp;#45;&amp;#45;&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;gt&amp;#45;one&lt;/span&gt;
&lt;span&gt;    &lt;/span&gt;&lt;span&gt;    &lt;/span&gt;&lt;span&gt;    &lt;/span&gt;&lt;span&gt;_:&lt;/span&gt;&lt;span&gt; &lt;/span&gt;s n2 &amp;gt; n2
        &lt;span&gt;is&lt;/span&gt;
&lt;span&gt;    &lt;/span&gt;&lt;span&gt;    &lt;/span&gt;&lt;span&gt;    &lt;/span&gt;&lt;span&gt;_:&lt;/span&gt;&lt;span&gt; &lt;/span&gt;s s n2 &amp;gt; s n2 &lt;span&gt;by&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;rule&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;gt&amp;#45;one&lt;/span&gt;
        &lt;span&gt;end case&lt;/span&gt;

        &lt;span&gt;case rule&lt;/span&gt;
&lt;span&gt;    &lt;/span&gt;&lt;span&gt;    &lt;/span&gt;&lt;span&gt;    &lt;/span&gt;&lt;span&gt;g1:&lt;/span&gt;&lt;span&gt; &lt;/span&gt;n11 &amp;gt; n2
&lt;span&gt;    &lt;/span&gt;&lt;span&gt;    &lt;/span&gt;&lt;span&gt;    &lt;/span&gt;&lt;span&gt;&amp;#45;&amp;#45;&amp;#45;&amp;#45;&amp;#45;&amp;#45;&amp;#45;&amp;#45;&amp;#45;&amp;#45;&amp;#45;&amp;#45;&amp;#45;&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;gt&amp;#45;more&lt;/span&gt;
&lt;span&gt;    &lt;/span&gt;&lt;span&gt;    &lt;/span&gt;&lt;span&gt;    &lt;/span&gt;&lt;span&gt;_:&lt;/span&gt;&lt;span&gt; &lt;/span&gt;s n11 &amp;gt; n2
        &lt;span&gt;is&lt;/span&gt;
&lt;span&gt;    &lt;/span&gt;&lt;span&gt;    &lt;/span&gt;&lt;span&gt;    &lt;/span&gt;&lt;span&gt;g2:&lt;/span&gt;&lt;span&gt; &lt;/span&gt;s n11 &amp;gt; s n2 &lt;span&gt;by&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;induction hypothesis&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;on &lt;/span&gt;&lt;span&gt;g1&lt;/span&gt;
&lt;span&gt;    &lt;/span&gt;&lt;span&gt;    &lt;/span&gt;&lt;span&gt;    &lt;/span&gt;&lt;span&gt;_:&lt;/span&gt;&lt;span&gt; &lt;/span&gt;s s n11 &amp;gt; s n2 &lt;span&gt;by&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;rule&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;gt&amp;#45;more&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;on &lt;/span&gt;&lt;span&gt;g2&lt;/span&gt;
        &lt;span&gt;end case&lt;/span&gt;
    &lt;span&gt;end induction&lt;/span&gt;
&lt;span&gt;end theorem&lt;/span&gt;
&lt;/span&gt;&lt;/pre&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;
&lt;/div&gt;
&lt;h3&gt;Conclusion&lt;/h3&gt;
&lt;p&gt;I realize this was a bit of a deviation from my normal semi&amp;#45;practical posts, but I think it was still a journey well worth taking.&amp;nbsp; If you&amp;#8217;re working as a serious developer in this industry, I strongly suggest that you find yourself a good formal language and/or type theory textbook (&lt;a href=&quot;http://www.amazon.com/Types-Programming-Languages-Benjamin-Pierce/dp/0262162091/ref=pd_bbs_sr_1?ie=UTF8&amp;s=books&amp;qid=1228110398&amp;sr=8-1&quot;&gt;might I recommend?&lt;/a&gt;) and follow it through the best that you can.&amp;nbsp; The understanding of how languages are formally constructed and the mental circuits to create those proofs yourself will have a surprisingly powerful impact on your day&amp;#45;to&amp;#45;day programming.&amp;nbsp; Knowing how the properties of a language are proven provides tremendous illumination into why that language is the way it is and somtimes how it can be made better.&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Credit:&lt;/b&gt; Examples in this post drawn rather unimaginatively from &lt;a href=&quot;http://www.cs.uwm.edu/~boyland/&quot;&gt;Dr. John Boyland&amp;#8217;s&lt;/a&gt; excellent course in type theory.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;http://www.cs.cmu.edu/~aldrich/SASyLF/&quot;&gt;SASyLF Main Page&lt;/a&gt; at Carnegie Mellon University&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://www.codecommit.com/blog/misc/math.slf&quot;&gt;Download math.slf&lt;/a&gt; (the full greater&amp;#45;than example)&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://www.cs.cmu.edu/~aldrich/SASyLF/fdpe08.pdf&quot;&gt;Further reading&amp;#8230;&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;</content>
		<author>
			<name>Code Commit</name>
			<uri>http://www.codecommit.com/blog</uri>
		</author>
		<source>
			<title type="html">Code Commit » Scala</title>
			<subtitle type="html">(permanently in beta)</subtitle>
			<link rel="self" href="http://www.codecommit.com/blog/category/scala/feed"/>
			<id>http://www.codecommit.com/blog/category/scala/feed</id>
			<updated>2008-12-01T08:20:19+00:00</updated>
		</source>
	</entry>

	<entry xml:lang="en">
		<title type="html">ObserveFunctorMonad</title>
		<link href="http://blog.tmorris.net/observefunctormonad/"/>
		<id>http://blog.tmorris.net/?p=457</id>
		<updated>2008-11-30T08:58:51+00:00</updated>
		<content type="html">&lt;p&gt;An exercise arising from an IRC discussion in #scala:&lt;/p&gt;

&lt;div class=&quot;wp_syntax&quot;&gt;&lt;div class=&quot;code&quot;&gt;&lt;pre class=&quot;scala&quot;&gt;&lt;span&gt;trait&lt;/span&gt; Functor&lt;span&gt;&amp;#91;&lt;/span&gt;F&lt;span&gt;&amp;#91;&lt;/span&gt;&lt;span&gt;_&lt;/span&gt;&lt;span&gt;&amp;#93;&lt;/span&gt;&lt;span&gt;&amp;#93;&lt;/span&gt; &lt;span&gt;&amp;#123;&lt;/span&gt;
  &lt;span&gt;def&lt;/span&gt; fmap&lt;span&gt;&amp;#91;&lt;/span&gt;A, B&lt;span&gt;&amp;#93;&lt;/span&gt;&lt;span&gt;&amp;#40;&lt;/span&gt;fa&lt;span&gt;:&lt;/span&gt; F&lt;span&gt;&amp;#91;&lt;/span&gt;A&lt;span&gt;&amp;#93;&lt;/span&gt;, f&lt;span&gt;:&lt;/span&gt; A &lt;span&gt;=&amp;gt;&lt;/span&gt; B&lt;span&gt;&amp;#41;&lt;/span&gt;&lt;span&gt;:&lt;/span&gt; F&lt;span&gt;&amp;#91;&lt;/span&gt;B&lt;span&gt;&amp;#93;&lt;/span&gt;
&lt;span&gt;&amp;#125;&lt;/span&gt;
&amp;nbsp;
&lt;span&gt;trait&lt;/span&gt; Monad&lt;span&gt;&amp;#91;&lt;/span&gt;M&lt;span&gt;&amp;#91;&lt;/span&gt;&lt;span&gt;_&lt;/span&gt;&lt;span&gt;&amp;#93;&lt;/span&gt;&lt;span&gt;&amp;#93;&lt;/span&gt; &lt;span&gt;&amp;#123;&lt;/span&gt;
  &lt;span&gt;def&lt;/span&gt; bind&lt;span&gt;&amp;#91;&lt;/span&gt;A, B&lt;span&gt;&amp;#93;&lt;/span&gt;&lt;span&gt;&amp;#40;&lt;/span&gt;ma&lt;span&gt;:&lt;/span&gt; M&lt;span&gt;&amp;#91;&lt;/span&gt;A&lt;span&gt;&amp;#93;&lt;/span&gt;, f&lt;span&gt;:&lt;/span&gt; A &lt;span&gt;=&amp;gt;&lt;/span&gt; M&lt;span&gt;&amp;#91;&lt;/span&gt;B&lt;span&gt;&amp;#93;&lt;/span&gt;&lt;span&gt;&amp;#41;&lt;/span&gt;&lt;span&gt;:&lt;/span&gt; M&lt;span&gt;&amp;#91;&lt;/span&gt;B&lt;span&gt;&amp;#93;&lt;/span&gt;
  &lt;span&gt;def&lt;/span&gt; pure&lt;span&gt;&amp;#91;&lt;/span&gt;A&lt;span&gt;&amp;#93;&lt;/span&gt;&lt;span&gt;&amp;#40;&lt;/span&gt;a&lt;span&gt;:&lt;/span&gt; A&lt;span&gt;&amp;#41;&lt;/span&gt;&lt;span&gt;:&lt;/span&gt; M&lt;span&gt;&amp;#91;&lt;/span&gt;A&lt;span&gt;&amp;#93;&lt;/span&gt;
&lt;span&gt;&amp;#125;&lt;/span&gt;
&amp;nbsp;
&lt;span&gt;object&lt;/span&gt; ObserveFunctorMonad &lt;span&gt;&amp;#123;&lt;/span&gt;
  &lt;span&gt;def&lt;/span&gt; observe&lt;span&gt;&amp;#91;&lt;/span&gt;K&lt;span&gt;&amp;#91;&lt;/span&gt;&lt;span&gt;_&lt;/span&gt;&lt;span&gt;&amp;#93;&lt;/span&gt;&lt;span&gt;&amp;#93;&lt;/span&gt;&lt;span&gt;&amp;#40;&lt;/span&gt;m&lt;span&gt;:&lt;/span&gt; Monad&lt;span&gt;&amp;#91;&lt;/span&gt;K&lt;span&gt;&amp;#93;&lt;/span&gt;&lt;span&gt;&amp;#41;&lt;/span&gt;&lt;span&gt;:&lt;/span&gt; Functor&lt;span&gt;&amp;#91;&lt;/span&gt;K&lt;span&gt;&amp;#93;&lt;/span&gt; &lt;span&gt;=&lt;/span&gt; error&lt;span&gt;&amp;#40;&lt;/span&gt;&lt;span&gt;&amp;quot;your homework&amp;quot;&lt;/span&gt;&lt;span&gt;&amp;#41;&lt;/span&gt;
&lt;span&gt;&amp;#125;&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;</content>
		<author>
			<name>Tony Morris</name>
			<uri>http://blog.tmorris.net</uri>
		</author>
		<source>
			<title type="html">λ Tony’s blog λ</title>
			<subtitle type="html">The weblog of Tony Morris</subtitle>
			<link rel="self" href="http://blog.tmorris.net/feed/"/>
			<id>http://blog.tmorris.net/feed/</id>
			<updated>2008-12-03T07:40:30+00:00</updated>
		</source>
	</entry>

	<entry xml:lang="en">
		<title type="html">Ubuntu released 8.10 knowing there was a nasty defect</title>
		<link href="http://blog.lostlake.org/index.php?/archives/86-Ubuntu-released-8.10-knowing-there-was-a-nasty-defect.html"/>
		<id>http://blog.lostlake.org/index.php?/archives/86-guid.html</id>
		<updated>2008-11-30T04:29:29+00:00</updated>
		<content type="html">&lt;p&gt;I had a rant about Ubuntu 8.10 being a buggy release.  Turns out that the Canonical people &lt;a href=&quot;https://bugs.launchpad.net/ubuntu/+bug/276990&quot;&gt;&lt;b&gt;knew&lt;/b&gt; about the defect&lt;/a&gt; and release Intrepid &lt;i&gt;anyway&lt;/i&gt;.  
The problem impacts about 10% of modern laptops... ones with the most common Intel WiFi chipset.  The defect has not been fixed.  The workaround doesn't work.
What are these people thinking?&lt;/p&gt;</content>
		<author>
			<name>David Pollak</name>
			<email>nospam@example.com</email>
			<uri>http://blog.lostlake.org/</uri>
		</author>
		<source>
			<title type="html">David Pollak's Blog</title>
			<subtitle type="html">Information, experiences, rants...</subtitle>
			<link rel="self" href="http://blog.lostlake.org/index.php?/feeds/index.rss2"/>
			<id>http://blog.lostlake.org/index.php?/feeds/index.rss2</id>
			<updated>2008-12-01T05:20:15+00:00</updated>
		</source>
	</entry>

	<entry xml:lang="en">
		<title type="html">Why Functional Programming Matters in short prose</title>
		<link href="http://blog.tmorris.net/why-functional-programming-matters-in-short-prose/"/>
		<id>http://blog.tmorris.net/?p=451</id>
		<updated>2008-11-30T01:35:51+00:00</updated>
		<content type="html">&lt;p&gt;&lt;a href=&quot;http://www.md.chalmers.se/~rjmh/Papers/whyfp.html&quot;&gt;Why Functional Programming Matters&lt;/a&gt; paraphrased &amp;mdash; a result of a discussion in an IRC channel. Others may find value.&lt;/p&gt;
&lt;p&gt;A program may be represented as a function that accepts some input and produces some outputλ This function may be composed of parts; other functions and values.&lt;/p&gt;
&lt;p&gt;Suppose any function that exists. I will suppose one that is made of parts A, B, C and D. I might denote this A ∘ B ∘ C ∘ D. Now suppose you desire a function that is made of parts A, B, C and E. Then the effort required for your function should be proportional to the effort required for E alone.&lt;/p&gt;
&lt;p&gt;The closer you are to achieving this objective for any function, the closer you are to the essence of (pure) functional programming. This exists independently of the programming language, though programming languages will vary significantly in the degree to which they accommodate this objective.&lt;/p&gt;
&lt;p&gt;Imperative programming &amp;mdash; specifically the scope of a destructive update &amp;mdash; is the anti-thesis of this objective.&lt;/p&gt;</content>
		<author>
			<name>Tony Morris</name>
			<uri>http://blog.tmorris.net</uri>
		</author>
		<source>
			<title type="html">λ Tony’s blog λ</title>
			<subtitle type="html">The weblog of Tony Morris</subtitle>
			<link rel="self" href="http://blog.tmorris.net/feed/"/>
			<id>http://blog.tmorris.net/feed/</id>
			<updated>2008-12-03T07:40:30+00:00</updated>
		</source>
	</entry>

	<entry xml:lang="en">
		<title type="html" xml:lang="de">Some Wicke[dt] Scala</title>
		<link href="http://www.footprint.de/fcc/2008/11/some-wicket-scala/"/>
		<id>http://www.footprint.de/fcc/?p=17</id>
		<updated>2008-11-29T18:45:27+00:00</updated>
		<content type="html" xml:lang="de">&lt;p&gt;&lt;a title=&quot;Apache Wicket&quot; href=&quot;http://wicket.apache.org/&quot; target=&quot;_blank&quot;&gt;Apache Wicket&lt;/a&gt; is a cool web framework to develop with. I&amp;#8217;m in that business for some time now and I still haven&amp;#8217;t found any nicer - really! JSF is no match at all, and since I&amp;#8217;m doing most of my programming in Scala I&amp;#8217;d taken a brief look at &lt;a title=&quot;Lift&quot; href=&quot;http://www.liftweb.net/&quot; target=&quot;_blank&quot;&gt;Lift&lt;/a&gt;. But that&amp;#8217;s not mine, either. Everything in Wicket is ad-hoc reusable, that&amp;#8217;s what I like best about it. And I think of Wicket and Scala as the perfect combination to develop with: Scala&amp;#8217;s traits allow adding and overriding things so easy to Wicket components that it&amp;#8217;s just a joy!&lt;/p&gt;
&lt;p&gt;I want to add some foundations to above statements, so be prepared for some tough Wicket internal stuff - easily written in Scala! And for the readers still developing Wicket applications in Java: You might find the resulting library equally useful and should be able to use it from Java as well.&lt;/p&gt;
&lt;h3&gt;Enter the Quest&lt;/h3&gt;
&lt;p&gt;You may have found yourself in need to preprocess the markup for your Wicket components. Typically, you like using &lt;a title=&quot;FreeMarker Templating Library&quot; href=&quot;http://freemarker.org/&quot; target=&quot;_blank&quot;&gt;FreeMarker&lt;/a&gt; or &lt;a title=&quot;Velocity Templating Library&quot; href=&quot;http://velocity.apache.org/&quot; target=&quot;_blank&quot;&gt;Velocity&lt;/a&gt; for that. There are Wicket projects which provide you with some kind of support to do so. But those only go half the way. You can load template files and process them, but you can&amp;#8217;t add Wicket components in them! Actually you could using &lt;code&gt;&amp;lt;wicket:component&amp;gt;&lt;/code&gt; - but that&amp;#8217;s a) not officially supported and b) doesn&amp;#8217;t work when adding components with Ajax behaviors, since those components are coming in in a late stage in Wicket&amp;#8217;s rendering scheme. Suppose you want to add some self-updating RSS feed panels based on some markup coming from a database you&amp;#8217;re lost here.&lt;/p&gt;
&lt;h3&gt;The solution: &lt;em&gt;Dynamo&lt;/em&gt;&lt;/h3&gt;
&lt;p&gt;I had such a task and found myself writing a generalized template engine with support for dynamic Wicket components. Here&amp;#8217;s a short code example how it&amp;#8217;s working:&lt;/p&gt;

&lt;div class=&quot;wp_codebox_msgheader&quot;&gt;&lt;span class=&quot;right&quot;&gt;&lt;sup&gt;&lt;a href=&quot;http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples&quot; target=&quot;_blank&quot; title=&quot;WP-CodeBox HowTo?&quot;&gt;&lt;span&gt;?&lt;/span&gt;&lt;/a&gt;&lt;/sup&gt;&lt;/span&gt;&lt;span class=&quot;left&quot;&gt;&lt;a href=&quot;javascript:;&quot;&gt;View Code&lt;/a&gt; SCALA&lt;/span&gt;&lt;div class=&quot;codebox_clear&quot;&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;wp_codebox&quot;&gt;&lt;table width=&quot;100%&quot;&gt;&lt;tr id=&quot;p174&quot;&gt;&lt;td class=&quot;code&quot; id=&quot;p17code4&quot;&gt;&lt;pre class=&quot;scala&quot;&gt;&lt;span&gt;class&lt;/span&gt; FreemarkerApplication &lt;span&gt;extends&lt;/span&gt; WebApplication &lt;span&gt;with&lt;/span&gt; Dynamo &lt;span&gt;&amp;#123;&lt;/span&gt;
  &lt;span&gt;def&lt;/span&gt; getTemplateEngine&lt;span&gt;:&lt;/span&gt; TemplateEngine &lt;span&gt;=&lt;/span&gt; &lt;span&gt;new&lt;/span&gt; FreemarkerEngine&lt;span&gt;&amp;#40;&lt;/span&gt; appPath, &lt;span&gt;new&lt;/span&gt; Properties, Locale.&lt;span&gt;GERMAN&lt;/span&gt; &lt;span&gt;&amp;#41;&lt;/span&gt;
  &lt;span&gt;def&lt;/span&gt; getHomePage &lt;span&gt;=&lt;/span&gt; classOf&lt;span&gt;&amp;#91;&lt;/span&gt;FreemarkerDynamoPage&lt;span&gt;&amp;#93;&lt;/span&gt;
&lt;span&gt;&amp;#125;&lt;/span&gt;
&amp;nbsp;
&lt;span&gt;class&lt;/span&gt; FreemarkerPage &lt;span&gt;extends&lt;/span&gt; WebPage &lt;span&gt;with&lt;/span&gt; TemplateContainer &lt;span&gt;&amp;#123;&lt;/span&gt;
  &lt;span&gt;val&lt;/span&gt; getTemplateName &lt;span&gt;=&lt;/span&gt; &lt;span&gt;&amp;quot;DynamoPage.ftl&amp;quot;&lt;/span&gt;
  &lt;span&gt;val&lt;/span&gt; getParameterMap &lt;span&gt;=&lt;/span&gt; &lt;span&gt;new&lt;/span&gt; java.&lt;span&gt;util&lt;/span&gt;.&lt;span&gt;Map&lt;/span&gt;&lt;span&gt;&amp;#91;&lt;/span&gt;String,AnyRef&lt;span&gt;&amp;#93;&lt;/span&gt;
&lt;span&gt;&amp;#125;&lt;/span&gt;
&amp;nbsp;
&lt;span&gt;class&lt;/span&gt; FreemarkerDynamoPage &lt;span&gt;extends&lt;/span&gt; FreemarkerPage &lt;span&gt;with&lt;/span&gt; DynamicComponentContainer&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;That&amp;#8217;s it! All logic is hidden behind the scenes, you just have to know it works. Your dynamic code might add components in the following way:&lt;/p&gt;

&lt;div class=&quot;wp_codebox_msgheader&quot;&gt;&lt;span class=&quot;right&quot;&gt;&lt;sup&gt;&lt;a href=&quot;http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples&quot; target=&quot;_blank&quot; title=&quot;WP-CodeBox HowTo?&quot;&gt;&lt;span&gt;?&lt;/span&gt;&lt;/a&gt;&lt;/sup&gt;&lt;/span&gt;&lt;span class=&quot;left&quot;&gt;&lt;a href=&quot;javascript:;&quot;&gt;View Code&lt;/a&gt; HTML&lt;/span&gt;&lt;div class=&quot;codebox_clear&quot;&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;wp_codebox&quot;&gt;&lt;table width=&quot;100%&quot;&gt;&lt;tr id=&quot;p175&quot;&gt;&lt;td class=&quot;code&quot; id=&quot;p17code5&quot;&gt;&lt;pre class=&quot;html&quot;&gt;    &amp;lt;h3&amp;gt;Dynamic Wicket Components:&amp;lt;/h3&amp;gt;
    &amp;lt;#list StringList as s&amp;gt;
      &amp;lt;dynComponent
        class=&amp;quot;de.footprint.wicket.application.dynamo.TextPanel&amp;quot;
        label=&amp;quot;${s}&amp;quot; /&amp;gt;
    &amp;lt;/#list&amp;gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/div&gt;

&lt;h3&gt;But how?&lt;/h3&gt;
&lt;p&gt;There were three tasks to accomplish. First was to define a general interface to call the processed template file. That wasn&amp;#8217;t too difficult:&lt;/p&gt;

&lt;div class=&quot;wp_codebox_msgheader&quot;&gt;&lt;span class=&quot;right&quot;&gt;&lt;sup&gt;&lt;a href=&quot;http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples&quot; target=&quot;_blank&quot; title=&quot;WP-CodeBox HowTo?&quot;&gt;&lt;span&gt;?&lt;/span&gt;&lt;/a&gt;&lt;/sup&gt;&lt;/span&gt;&lt;span class=&quot;left&quot;&gt;&lt;a href=&quot;javascript:;&quot;&gt;View Code&lt;/a&gt; SCALA&lt;/span&gt;&lt;div class=&quot;codebox_clear&quot;&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;wp_codebox&quot;&gt;&lt;table width=&quot;100%&quot;&gt;&lt;tr id=&quot;p176&quot;&gt;&lt;td class=&quot;code&quot; id=&quot;p17code6&quot;&gt;&lt;pre class=&quot;scala&quot;&gt;&lt;span&gt;trait&lt;/span&gt; TemplateEngine &lt;span&gt;&amp;#123;&lt;/span&gt;
  &lt;span&gt;@&lt;/span&gt;throws&lt;span&gt;&amp;#40;&lt;/span&gt; classOf&lt;span&gt;&amp;#91;&lt;/span&gt;ResourceStreamNotFoundException&lt;span&gt;&amp;#93;&lt;/span&gt; &lt;span&gt;&amp;#41;&lt;/span&gt;
  &lt;span&gt;def&lt;/span&gt; processTemplate&lt;span&gt;&amp;#40;&lt;/span&gt; templateName&lt;span&gt;:&lt;/span&gt; String, parameter&lt;span&gt;:&lt;/span&gt; java.&lt;span&gt;util&lt;/span&gt;.&lt;span&gt;Map&lt;/span&gt;&lt;span&gt;&amp;#91;&lt;/span&gt;String,AnyRef&lt;span&gt;&amp;#93;&lt;/span&gt;, locale&lt;span&gt;:&lt;/span&gt; Locale &lt;span&gt;&amp;#41;&lt;/span&gt;&lt;span&gt;:&lt;/span&gt; String
&amp;nbsp;
  &lt;span&gt;def&lt;/span&gt; resetCache&lt;span&gt;:&lt;/span&gt; Unit
&lt;span&gt;&amp;#125;&lt;/span&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Second was to hook into the markup loader to call on the engine whenever a container of type &lt;code&gt;TemplateContainer&lt;/code&gt; was required. The &lt;code&gt;Dynamo&lt;/code&gt; trait registers a customzed &lt;code&gt;MarkupCache&lt;/code&gt; with the &lt;code&gt;Application&lt;/code&gt; which just does that.&lt;/p&gt;
&lt;p&gt;The third task was to add the dynamic component stuff. Now it got a bit nasty. The resource stream had to be filtered for components added by the template engine - and that had to happen before Wicket got it&amp;#8217;s hand on the resources, i.e. &lt;code&gt;WicketTagIdentifier&lt;/code&gt; got on the resource. So, the markup had to be loaded manually beforehand and the additional components had to be given unique (and stable) wicket:id&amp;#8217;s. Having all that, the components only had to be created and added with their correct &lt;code&gt;wicket:id&lt;/code&gt;. Easy, huh?&lt;/p&gt;
&lt;p&gt;The nice thing with Scala is, you can just hide all these tasks in traits and add them to the components. &lt;code&gt;onBeforeRender&lt;/code&gt; will just be overriden and mixed in, so the functionality is magically just there.&lt;/p&gt;
&lt;h3&gt;Famous last words&lt;/h3&gt;
&lt;p&gt;The code is here: &lt;a href=&quot;http://www.footprint.de/fcc/wp-content/uploads/2008/11/wicket-dynamo.zip&quot;&gt;Dynamo&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;To run the examples you have to use &lt;code&gt;mvn resin:run&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;It includes general support for FreeMarker and Velocity, but this approach can easily be integrated with any other markup source provider.&lt;/p&gt;
&lt;p&gt;I hope you find this useful and get some ideas how Scala/Wicket can boost your code - not only in function but also in readability.&lt;/p&gt;
&lt;p&gt;&amp;#8212; Jan. &lt;/p&gt;</content>
		<author>
			<name>Jan Kriesten</name>
			<uri>http://www.footprint.de/fcc</uri>
		</author>
		<source>
			<title type="html">footprint code coverage » Scala</title>
			<subtitle type="html">Thoughts and rants on programming.</subtitle>
			<link rel="self" href="http://www.footprint.de/fcc/tag/scala/feed"/>
			<id>http://www.footprint.de/fcc/tag/scala/feed</id>
			<updated>2008-11-29T19:20:18+00:00</updated>
		</source>
	</entry>

	<entry xml:lang="en">
		<title type="html">Mount Mee State Forest Campgrounds</title>
		<link href="http://blog.tmorris.net/mount-mee-state-forest-campgrounds/"/>
		<id>http://blog.tmorris.net/?p=430</id>
		<updated>2008-11-29T10:52:51+00:00</updated>
		<content type="html">&lt;p&gt;I am an avid GPS user and I visit &lt;a href=&quot;http://www.epa.qld.gov.au/projects/park/index.cgi?parkid=63&quot;&gt;Mount Mee State Forest&lt;/a&gt; regularly on my dirt bike (Husqvarna TE450). I encounter queries on forums for the locations of &lt;a href=&quot;http://www.epa.qld.gov.au/parks_and_forests/find_a_park_or_forest/mount_mee_state_forest_and_forest_reserve__camping_information/&quot;&gt;the campgrounds in this forest&lt;/a&gt;, so here they are:&lt;/p&gt;
&lt;p&gt;Neurum Creek Campground&lt;br /&gt;
-27.061853° 152.696228°&lt;br /&gt;
&lt;em&gt;-27°03&amp;#8242;42.67&amp;#8243; 152°41&amp;#8242;46.42&amp;#8243;&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;Archer Campground&lt;br /&gt;
-27.016317° 152.697767°&lt;br /&gt;
&lt;em&gt;-27°00&amp;#8242;58.74&amp;#8243; 152°41&amp;#8242;51.96&amp;#8243;&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;You can get to Neurum Creek Campground by taking &lt;a href=&quot;http://maps.google.com/maps?f=q&amp;hl=en&amp;geocode=&amp;q=sellin+road+dayboro+queensland&amp;sll=35.338111,-81.860311&amp;sspn=0.013181,0.027874&amp;ie=UTF8&amp;ll=-27.182835,152.815747&amp;spn=0.007187,0.013937&amp;z=17&quot;&gt;Sellin Road&lt;/a&gt; then turning onto Neurum Creek Road and following it north. Archer Campground can be found by taking Sellin Road then Lovedays Road, however, it is easier to approach from the north side of the forest and head south. Both of these campgrounds require a permit through the Environmental Protection Agency (EPA) or you can &lt;a href=&quot;https://www.epa.qld.gov.au/parks/iaparks/gds/IAGDS050.jsp?quickParkId=3&quot;&gt;book online&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;There is another campground called &lt;a href=&quot;http://www.ncbr.com.au/&quot;&gt;Neurum Creek Bush Retreat&lt;/a&gt; but this is a &lt;strong&gt;different&lt;/strong&gt; campground to those two mentioned. It is privately owned and I have personally stayed a weekend there and recommend it, especially if you have children or want a weekend of dirt bike riding (though the operators are understandably strict about noise control) since you can head south into Mount Mee State Forest or head over to &lt;a href=&quot;http://www.epa.qld.gov.au/projects/park/index.cgi?parkid=7&quot;&gt;Beerburrum State Forest&lt;/a&gt;. This campground is even further north of the state forest than the other two (which are situated in the forest boundaries), but is a short ride on gravel to the forest entrance.&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;http://projects.tmorris.net/public/maps/gpx/Mount%20Mee%20State%20Forest.gpx&quot;&gt;&lt;br /&gt;
Here&lt;/a&gt; is a reasonably comprehensive GPX file of Mount Mee State Forest including the two campgrounds and many dirt trails. I&amp;#8217;d upload it to OpenStreetMap but I have yet to figure that out.&lt;/p&gt;
&lt;p&gt;I use a &lt;a href=&quot;https://buy.garmin.com/shop/shop.do?pID=309#gpsmap60cx&quot;&gt;Garmin 60Cx&lt;/a&gt; unit.&lt;/p&gt;
&lt;p&gt;I hope this helps &lt;img src=&quot;http://blog.tmorris.net/wp-includes/images/smilies/icon_wink.gif&quot; alt=&quot;;)&quot; class=&quot;wp-smiley&quot; /&gt;&lt;/p&gt;</content>
		<author>
			<name>Tony Morris</name>
			<uri>http://blog.tmorris.net</uri>
		</author>
		<source>
			<title type="html">λ Tony’s blog λ</title>
			<subtitle type="html">The weblog of Tony Morris</subtitle>
			<link rel="self" href="http://blog.tmorris.net/feed/"/>
			<id>http://blog.tmorris.net/feed/</id>
			<updated>2008-12-03T07:40:30+00:00</updated>
		</source>
	</entry>

	<entry xml:lang="en">
		<title type="html">scalaimage2</title>
		<link href="http://justindomke.wordpress.com/2008/11/29/mandelbrot-in-scala/"/>
		<id>http://justindomke.wordpress.com/?p=138</id>
		<updated>2008-11-29T02:23:10+00:00</updated>
		<content type="html">&lt;div class=&quot;snap_preview&quot;&gt;&lt;br /&gt;&lt;p&gt;With my growing frustration with Matlab, I&amp;#8217;ve been looking for a while for a language that was&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Garbage collected&lt;/li&gt;
&lt;li&gt;Good notation for numerical computation&lt;/li&gt;
&lt;li&gt;Fast enough for numerical computation&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;After a long search, I think I&amp;#8217;ve finally found my home in &lt;a href=&quot;http://www.scala-lang.org/&quot;&gt;Scala&lt;/a&gt;.  Today I did a very trivial, self-contained computation of some images of the &lt;a href=&quot;http://en.wikipedia.org/wiki/Mandelbrot_set&quot;&gt;Mandelbrot set&lt;/a&gt; to test it out.&lt;/p&gt;
&lt;p&gt;When learning Scala, I couldn&amp;#8217;t find enough examples of numerical stuff, so I thought I would post this here for those potentially interested.  Here&amp;#8217;s a first attempt:&lt;/p&gt;
&lt;pre&gt;import java.io._
import java.lang.Math

object mandelbrot {
  // tiny complex number class including syntactic sugar for basic operations
  class Complex(val a: Double, val b: Double){
    // represents the complex number a + b*i
    def +(that: Complex) = new Complex(this.a+that.a,this.b+that.b)
    def *(that: Complex) = new Complex(this.a*that.a-this.b*that.b,this.a*that.b+that.a*this.b)
    def abs() = Math.sqrt(this.a*this.a + this.b*this.b)
  }

  def run(n: Int, level: Int) : Unit = {
    val out = new FileOutputStream(&quot;scalaimage.pgm&quot;)
    out.write((&quot;P5\n&quot;+n+&quot; &quot;+n+&quot;\n255\n&quot;).getBytes())

    for {y0 &amp;lt;- 0 until n
	 x0 &amp;lt;- 0 until n }{
	   // y0 and x0 are in pixel integers
	   // x  and y  are real number coordinates
	   val x = -2.0 + x0*3.0/n
	   val y = -1.5 + y0*3.0/n

	   var z = new Complex(0,0)
	   var c = new Complex(x,y)
	   for(i &amp;lt;- 0 until level)
	     z = z*z + c 

	   if (z.abs &amp;lt; 2)
	     out.write(0);
	   else
	     out.write(255);
	 }
    out.close()
  }

  def main(args: Array[String]) {
    run(Integer.parseInt(args(1)), Integer.parseInt(args(0)))
  }
}&lt;/pre&gt;
&lt;p&gt;Not bad, right?  Notice how painlessly we create the Complex class, along with the natural syntax for manipulating the numbers.  What&amp;#8217;s more, the result is very fast.  For a 2048 by 2048 image, I get results in less than 30 seconds.  (Just consider running this algorithm in Matlab.  Ha!)&lt;/p&gt;
&lt;p&gt;Save this to a file &amp;#8220;mandelbrot1.scala&amp;#8221;, and compile and run with:&lt;/p&gt;
&lt;pre&gt;scalac mandelbrot1.scala
scala mandelbrot 100 2048&lt;/pre&gt;
&lt;p&gt;The first argument is many times to try the mandelbrot iteration, and the second argument is how big of an image to output.  The result is:&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;http://justindomke.files.wordpress.com/2008/11/scalaimage11.png&quot;&gt;&lt;img class=&quot;alignnone size-full wp-image-140&quot; title=&quot;scalaimage11&quot; src=&quot;http://justindomke.files.wordpress.com/2008/11/scalaimage11.png?w=400&amp;h=400&quot; alt=&quot;scalaimage11&quot; width=&quot;400&quot; height=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;(I manually converted the .pgm to .png to save space&amp;#8211; click to get the full resolution version.)&lt;/p&gt;
&lt;p&gt;A slightly more complex version follows.  I added notation for the operators *= and +=, which speeds things up by about 10%.  I also now color the pixels by how many iterations it takes the mandelbrot iterations to diverge.&lt;/p&gt;
&lt;pre&gt;import java.io._
import java.lang.Math

object mandelbrot {
  // tiny complex number class including syntactic sugar for basic operations
  class Complex(var a: Double, var b: Double){
    // represents the complex number a + b*i
    def +(that: Complex) = new Complex(this.a+that.a,this.b+that.b)
    def *(that: Complex) = new Complex(this.a*that.a-this.b*that.b,this.a*that.b+that.a*this.b)
    def abs() = Math.sqrt(this.a*this.a + this.b*this.b)
    def *=(that: Complex) ={
      val newa = this.a*that.a-this.b*that.b
      this.b = this.a*that.b+that.a*this.b
      this.a = newa
      this
    }
    def +=(that: Complex)={
      this.a += that.a
      this.b += that.b
      this
    }
  }

  def run(n: Int, level: Int) : Unit = {
    val out = new FileOutputStream(&quot;scalaimage.pgm&quot;)
    out.write((&quot;P5\n&quot;+n+&quot; &quot;+n+&quot;\n255\n&quot;).getBytes())

    for {y0 &amp;lt;- 0 until n
	 x0 &amp;lt;- 0 until n }{
	   // y0 and x0 are in pixel integers
	   // x  and y  are real number coordinates
	   val x = -2.0 + x0*3.0/n
	   val y = -1.5 + y0*3.0/n

	   var z = new Complex(0,0)
	   var c = new Complex(x,y)
	   var i = 0
	   do {
	     z *= z
	     z += c
	     i += 1
	   } while( z.abs &amp;lt; 2 &amp;amp;&amp;amp; i &amp;lt; level)

	   if (z.abs &amp;lt; 2)
	     out.write(0);
	   else
	     out.write( (i*255.0/level).toInt );
	 }
    out.close()
  }

  def main(args: Array[String]){
    run(Integer.parseInt(args(1)), Integer.parseInt(args(0)))
  }
}&lt;/pre&gt;
&lt;p&gt;Compile and run as before.  The output is:&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;http://justindomke.files.wordpress.com/2008/11/scalaimage2.png&quot;&gt;&lt;img class=&quot;alignnone size-full wp-image-141&quot; title=&quot;scalaimage2&quot; src=&quot;http://justindomke.files.wordpress.com/2008/11/scalaimage2.png?w=400&amp;h=400&quot; alt=&quot;scalaimage2&quot; width=&quot;400&quot; height=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;I&amp;#8217;m not sure how many people are using Scala for numerical applications, but it looks very good so far.  There are a few minor tricks that turn out to be incredibly convenient.  For example, if you define any function &lt;code&gt;func&lt;/code&gt; for some class a, in a normal language you would call it by&lt;/p&gt;
&lt;pre&gt;a.func(b).&lt;/pre&gt;
&lt;p&gt;Scala defines this, but also gives you automatically the notation&lt;/p&gt;
&lt;pre&gt;a func b.&lt;/pre&gt;
&lt;p&gt;Adding in Scala&amp;#8217;s non-mandatory type declarations (as above, notice that x0 and x aren&amp;#8217;t declared to be Int or Double) tricks for implicit conversion between types, and it looks like it is possible to recreate almost all of Matlab&amp;#8217;s synactic sugar for matrix manipulation, while actually allowing reasonable speed for non-vectorizable code, and reasonable facilities for abstraction. I hope to soon be an ex-Matlab user.&lt;/p&gt;
&lt;p&gt;The &lt;a href=&quot;http://code.google.com/p/scalala/&quot;&gt;scalala library&lt;/a&gt; looks very promising, though I haven&amp;#8217;t taken the time to install it yet, and it looks like absolutely no one is using it.  (dramage, give us some documentation!)&lt;/p&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;a rel=&quot;nofollow&quot; href=&quot;http://feeds.wordpress.com/1.0/gocomments/justindomke.wordpress.com/138/&quot;&gt;&lt;img alt=&quot;&quot; border=&quot;0&quot; src=&quot;http://feeds.wordpress.com/1.0/comments/justindomke.wordpress.com/138/&quot; /&gt;&lt;/a&gt; &lt;a rel=&quot;nofollow&quot; href=&quot;http://feeds.wordpress.com/1.0/godelicious/justindomke.wordpress.com/138/&quot;&gt;&lt;img alt=&quot;&quot; border=&quot;0&quot; src=&quot;http://feeds.wordpress.com/1.0/delicious/justindomke.wordpress.com/138/&quot; /&gt;&lt;/a&gt; &lt;a rel=&quot;nofollow&quot; href=&quot;http://feeds.wordpress.com/1.0/gostumble/justindomke.wordpress.com/138/&quot;&gt;&lt;img alt=&quot;&quot; border=&quot;0&quot; src=&quot;http://feeds.wordpress.com/1.0/stumble/justindomke.wordpress.com/138/&quot; /&gt;&lt;/a&gt; &lt;a rel=&quot;nofollow&quot; href=&quot;http://feeds.wordpress.com/1.0/godigg/justindomke.wordpress.com/138/&quot;&gt;&lt;img alt=&quot;&quot; border=&quot;0&quot; src=&quot;http://feeds.wordpress.com/1.0/digg/justindomke.wordpress.com/138/&quot; /&gt;&lt;/a&gt; &lt;a rel=&quot;nofollow&quot; href=&quot;http://feeds.wordpress.com/1.0/goreddit/justindomke.wordpress.com/138/&quot;&gt;&lt;img alt=&quot;&quot; border=&quot;0&quot; src=&quot;http://feeds.wordpress.com/1.0/reddit/justindomke.wordpress.com/138/&quot; /&gt;&lt;/a&gt; &lt;img alt=&quot;&quot; border=&quot;0&quot; src=&quot;http://stats.wordpress.com/b.gif?host=justindomke.wordpress.com&amp;blog=4009146&amp;post=138&amp;subd=justindomke&amp;ref=&amp;feed=1&quot; /&gt;&lt;/div&gt;</content>
		<author>
			<name>Justin Domke</name>
			<uri>http://justindomke.wordpress.com</uri>
		</author>
		<source>
			<title type="html">Justin Domke's Weblog » scala</title>
			<link rel="self" href="http://justindomke.wordpress.com/tag/scala/feed/"/>
			<id>http://justindomke.wordpress.com/tag/scala/feed/</id>
			<updated>2008-12-02T10:40:42+00:00</updated>
		</source>
	</entry>

	<entry>
		<title type="html">foldLeft in Scala, Little Schemer style</title>
		<link href="http://jackcoughonsoftware.blogspot.com/2008/11/foldleft-in-scala-little-schemer-style.html"/>
		<id>tag:blogger.com,1999:blog-34927953.post-9013350604538095988</id>
		<updated>2008-11-28T23:20:16+00:00</updated>
		<content type="html">I'm going to write up a Scala version of foldLeft in the style of &lt;a href=&quot;http://www.ccs.neu.edu/home/matthias/BTLS/&quot;&gt;The Little Schemer&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;What is 0 + (1 + 2 + 3)?&lt;br /&gt;&lt;br /&gt;&gt;6&lt;br /&gt;&lt;br /&gt;What is 0 + (1 + 2 + 3)?&lt;br /&gt;&lt;br /&gt;&gt;0 + 1 + (2 + 3)&lt;br /&gt;&lt;br /&gt;What is 0 + 1?&lt;br /&gt;&lt;br /&gt;&gt;1&lt;br /&gt;&lt;br /&gt;What is 1 + (2 + 3) ?&lt;br /&gt;&lt;br /&gt;&gt;1 + 2 + (3)&lt;br /&gt;&lt;br /&gt;What is 1 + 2? &lt;br /&gt;&lt;br /&gt;&gt;3&lt;br /&gt;&lt;br /&gt;What is 3 + (3)?&lt;br /&gt;&lt;br /&gt;&gt;3 + 3&lt;br /&gt;&lt;br /&gt;What is 3 + 3?&lt;br /&gt;&lt;br /&gt;&gt;6&lt;br /&gt;&lt;br /&gt;Are we done? &lt;br /&gt;&lt;br /&gt;&gt;No, we still haven't found out what foldLeft is.&lt;br /&gt;&lt;br /&gt;What is foldLeft?&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;def foldLeft[A, B](as: List[A], z: B)(f: (B, A) =&gt; B): B = {&lt;br /&gt;    as match {&lt;br /&gt;      case Nil =&gt; z&lt;br /&gt;      case x :: xs =&gt; foldLeft( f(z, x), xs )( f )&lt;br /&gt;    }&lt;br /&gt;  }&lt;/pre&gt;&lt;br /&gt;But that doesn't tell us much does it? Let's walk through an example.&lt;br /&gt;&lt;br /&gt;What is List( 1, 2, 3 )?&lt;br /&gt;&lt;br /&gt;&gt;List( 1, 2, 3 )&lt;br /&gt;&lt;br /&gt;What is foldLeft(a, 0){ (x,y) =&gt; x + y } when a is List( 1, 2, 3 )&lt;br /&gt;&lt;br /&gt;&gt;6 ... but why? Let's step through it together.&lt;br /&gt;&lt;br /&gt;What is the first question foldLeft asks about the list?&lt;br /&gt;&lt;br /&gt;&gt;case Nil &lt;br /&gt;&lt;br /&gt;Is a Nil?&lt;br /&gt;&lt;br /&gt;&gt;No, it's List( 1, 2, 3 ), so we ask the next question.&lt;br /&gt;&lt;br /&gt;What is the next question?&lt;br /&gt;&lt;br /&gt;&gt;case x :: xs&lt;br /&gt;&lt;br /&gt;What is the value of case x :: xs?&lt;br /&gt;&lt;br /&gt;&gt;true, because the list is not Nil, it contains one element x which is 1, followed by a list xs which is List(2,3).&lt;br /&gt;&lt;br /&gt;So what is the next step?&lt;br /&gt;&lt;br /&gt;&gt; foldLeft( xs, f(z, x) )( f )&lt;br /&gt;&lt;br /&gt;What is f( z, x )?&lt;br /&gt;&lt;br /&gt;&gt; Well, remember, we called foldLeft like so: foldLeft(a, 0){ (x,y) =&gt; x + y } &lt;br /&gt;&lt;br /&gt;And what is f?&lt;br /&gt;&lt;br /&gt;&gt; { (x,y) =&gt; x + y } &lt;br /&gt;&lt;br /&gt;Again, what is f( z, x )?&lt;br /&gt;&lt;br /&gt;&gt; f( 0, 1 )&lt;br /&gt;&gt; (0,1) =&gt; 0 + 1&lt;br /&gt;&gt; 1&lt;br /&gt;&lt;br /&gt;So what has foldLeft( xs, f(z, x) )( f ) become?&lt;br /&gt;&lt;br /&gt;&gt; foldLeft( List(2,3), 1 )( f )&lt;br /&gt;&lt;br /&gt;Now we recur into foldLeft. What is the first question foldLeft asks about the list?&lt;br /&gt;&lt;br /&gt;&gt;case Nil &lt;br /&gt;&lt;br /&gt;Is a Nil?&lt;br /&gt;&lt;br /&gt;&gt;No, it's List( 2, 3 ), so we ask the next question.&lt;br /&gt;&lt;br /&gt;What is the next question?&lt;br /&gt;&lt;br /&gt;&gt;case x :: xs&lt;br /&gt;&lt;br /&gt;What is the value of case x :: xs?&lt;br /&gt;&lt;br /&gt;&gt;true, because the list is not Nil, it contains one element x which is 2, followed by a list xs which is List(3).&lt;br /&gt;&lt;br /&gt;So what is the next step?&lt;br /&gt;&lt;br /&gt;&gt; foldLeft( xs, f(z, x) )( f )&lt;br /&gt;&lt;br /&gt;What is f( z, x )? Remember that z is now 1.&lt;br /&gt;&lt;br /&gt;&gt; f( 1, 2 )&lt;br /&gt;&gt; (1,2) =&gt; 1 + 3&lt;br /&gt;&gt; 3&lt;br /&gt;&lt;br /&gt;So what has foldLeft( xs, f(z, x) )( f ) become?&lt;br /&gt;&lt;br /&gt;&gt; foldLeft( List(3), 3 )( f )&lt;br /&gt;&lt;br /&gt;Now we recur into foldLeft. What is the first question foldLeft asks about the list?&lt;br /&gt;&lt;br /&gt;&gt;case Nil &lt;br /&gt;&lt;br /&gt;Is a Nil?&lt;br /&gt;&lt;br /&gt;&gt;No, it's List(3), so we ask the next question.&lt;br /&gt;&lt;br /&gt;What is the next question?&lt;br /&gt;&lt;br /&gt;&gt;case x :: xs&lt;br /&gt;&lt;br /&gt;What is the value of case x :: xs?&lt;br /&gt;&lt;br /&gt;&gt;true, because the list is not Nil, it contains one element x which is 3, followed by a list xs which is Nil.&lt;br /&gt;&lt;br /&gt;So what is the next step?&lt;br /&gt;&lt;br /&gt;&gt; foldLeft( xs, f(z, x) )( f )&lt;br /&gt;&lt;br /&gt;What is f( z, x )? Remember that z is now 3.&lt;br /&gt;&lt;br /&gt;&gt; f( 3, 3 )&lt;br /&gt;&gt; (3,3) =&gt; 3 + 3&lt;br /&gt;&gt; 6&lt;br /&gt;&lt;br /&gt;So what has foldLeft( xs, f(z, x) )( f ) become?&lt;br /&gt;&lt;br /&gt;&gt; foldLeft( Nil, 6 )( f )&lt;br /&gt;