<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Michid's Weblog</title>
	<atom:link href="http://michid.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://michid.wordpress.com</link>
	<description>Hacking Scala</description>
	<lastBuildDate>Tue, 27 Dec 2011 20:10:40 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='michid.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>Michid's Weblog</title>
		<link>http://michid.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://michid.wordpress.com/osd.xml" title="Michid&#039;s Weblog" />
	<atom:link rel='hub' href='http://michid.wordpress.com/?pushpress=hub'/>
		<item>
		<title>Json Jerk: a flexible JSON parser</title>
		<link>http://michid.wordpress.com/2011/12/09/json-jerk-a-flexible-json-parser/</link>
		<comments>http://michid.wordpress.com/2011/12/09/json-jerk-a-flexible-json-parser/#comments</comments>
		<pubDate>Fri, 09 Dec 2011 23:16:49 +0000</pubDate>
		<dc:creator>michid</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://michid.wordpress.com/?p=299</guid>
		<description><![CDATA[I just pushed Json Jerk to Github. Json Jerk is a flexible and fast JSON parser written in Java. It consists of several composable parts for tokenizing, (un)escaping, parsing, and handling of semantic actions. Furthermore it provides a light weight and type safe object model for JSON documents. Details and examples are in the readme [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=michid.wordpress.com&amp;blog=2538862&amp;post=299&amp;subd=michid&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I just pushed <a href="https://github.com/mduerig/json-jerk">Json Jerk</a> to Github. Json Jerk is a flexible and fast JSON parser written in Java. It consists of several composable parts for tokenizing, (un)escaping, parsing, and handling of semantic actions. Furthermore it provides a light weight and type safe object model for JSON documents.</p>
<p>Details and examples are in the <a href="https://github.com/mduerig/json-jerk/blob/master/README.md">readme</a> and in the <a href="https://github.com/mduerig/json-jerk/blob/master/src/test/java/michid/jsonjerk/Examples.java">test cases</a>.</p>
<p><strong>Update:</strong>I renamed the parser from Flex Json to Json Jerk due to a name clash with an <a href="http://flexjson.sourceforge.net/">existing project</a>.  </p>
<br />Filed under: <a href='http://michid.wordpress.com/category/uncategorized/'>Uncategorized</a>  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/michid.wordpress.com/299/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/michid.wordpress.com/299/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/michid.wordpress.com/299/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/michid.wordpress.com/299/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/michid.wordpress.com/299/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/michid.wordpress.com/299/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/michid.wordpress.com/299/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/michid.wordpress.com/299/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/michid.wordpress.com/299/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/michid.wordpress.com/299/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/michid.wordpress.com/299/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/michid.wordpress.com/299/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/michid.wordpress.com/299/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/michid.wordpress.com/299/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=michid.wordpress.com&amp;blog=2538862&amp;post=299&amp;subd=michid&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://michid.wordpress.com/2011/12/09/json-jerk-a-flexible-json-parser/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">michid</media:title>
		</media:content>
	</item>
		<item>
		<title>Union types</title>
		<link>http://michid.wordpress.com/2011/06/12/union-types/</link>
		<comments>http://michid.wordpress.com/2011/06/12/union-types/#comments</comments>
		<pubDate>Sun, 12 Jun 2011 13:55:54 +0000</pubDate>
		<dc:creator>michid</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Meta-Programming]]></category>
		<category><![CDATA[Scala]]></category>

		<guid isPermaLink="false">http://michid.wordpress.com/?p=283</guid>
		<description><![CDATA[In his recent blog post Miles Sabin came up with an ingenious way of expressing union types in Scala. A union type is the union of some types: its values are the union of the values of each of the individual types. In a nutshell he first defines the negation of types as and then [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=michid.wordpress.com&amp;blog=2538862&amp;post=283&amp;subd=michid&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>In his recent <a href="http://www.chuusai.com/2011/06/09/scala-union-types-curry-howard/">blog post</a> Miles Sabin came up with an ingenious way of expressing union types in Scala. A union type is the union of some types: its values are the union of the values of each of the individual types. </p>
<p>In a nutshell he first defines the negation of types as</p>
<p><pre class="brush: java;">
type ¬[A] = A =&gt; Nothing
</pre></p>
<p>and then the union of two types via De Morgan&#8217;s law</p>
<p><pre class="brush: java;">
type ∨[T, U] = ¬[¬[T] with ¬[U]]
</pre></p>
<p>With the following auxiliary constructs</p>
<p><pre class="brush: java;">
type ¬¬[A] = ¬[¬[A]]
type |∨|[T, U] = { type λ[X] = ¬¬[X] &lt;:&lt; (T ∨ U) }
    case s: String =&gt; s.length
}
</pre></p>
<p>union types can be used in a very intuitive way</p>
<p><pre class="brush: java;">
def size[T: (Int |∨| String)#λ](t: T) = t match {
    case i: Int =&gt; i
    case s: String =&gt; s.length
}

scala&gt; size(3)
res0: Int = 3

scala&gt; size(&quot;three&quot;)
res1: Int = 5

scala&gt; size(4.2)
:13: error: Cannot prove that ((Double) =&gt; Nothing) =&gt; Nothing &gt;: Nothing with (java.lang.String) =&gt; Nothing) =&gt; Nothing.
       size(4.2)
           ^
</pre></p>
<h4>&#8230; and beyond</h3>
<p>With type negation and disjunction from above, it becomes possible to express all types whose set of values can be expressed by a term in propositional calculus. But can we do better? That is, is it possible to express types which don&#8217;t have a corresponding term in propositional calculus?</p>
<p>Generalizing the type constructor ∨[T, U] to some arbitrary acceptor</p>
<p><pre class="brush: java;">
type Acceptor[T, U] = { type λ[X] = ... }
</pre></p>
<p>it becomes apparent, that all types for which there is a corresponding type level acceptor function are expressible. Since <a href="http://michid.wordpress.com/2010/01/29/scala-type-level-encoding-of-the-ski-calculus/">type level calculations in Scala are Turing complete</a>, it should be possible to find an acceptor for any recursive function. This means that &#8211; in theory at least &#8211; Scala&#8217;s type system is powerful enough to express any type whose set of values is recursive. </p>
<br />Filed under: <a href='http://michid.wordpress.com/category/uncategorized/'>Uncategorized</a> Tagged: <a href='http://michid.wordpress.com/tag/meta-programming/'>Meta-Programming</a>, <a href='http://michid.wordpress.com/tag/scala/'>Scala</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/michid.wordpress.com/283/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/michid.wordpress.com/283/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/michid.wordpress.com/283/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/michid.wordpress.com/283/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/michid.wordpress.com/283/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/michid.wordpress.com/283/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/michid.wordpress.com/283/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/michid.wordpress.com/283/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/michid.wordpress.com/283/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/michid.wordpress.com/283/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/michid.wordpress.com/283/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/michid.wordpress.com/283/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/michid.wordpress.com/283/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/michid.wordpress.com/283/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=michid.wordpress.com&amp;blog=2538862&amp;post=283&amp;subd=michid&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://michid.wordpress.com/2011/06/12/union-types/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">michid</media:title>
		</media:content>
	</item>
		<item>
		<title>Regular expression matching in &lt;100 lines of code</title>
		<link>http://michid.wordpress.com/2010/12/06/regular-expression-matching-in-100-lines-of-code/</link>
		<comments>http://michid.wordpress.com/2010/12/06/regular-expression-matching-in-100-lines-of-code/#comments</comments>
		<pubDate>Mon, 06 Dec 2010 23:23:46 +0000</pubDate>
		<dc:creator>michid</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Regular Expression]]></category>
		<category><![CDATA[Scala]]></category>

		<guid isPermaLink="false">http://michid.wordpress.com/?p=252</guid>
		<description><![CDATA[The recent discussion about the Yacc is dead paper on Lambda the Ultimate sparked my interest in regular expression derivatives. The original idea goes back to the paper Derivatives of Regular Expressions published in 1964 (!) by Janusz A. Brzozowski. For a more modern treatment of the topic see Regular-expression derivatives reexamined. The derivative of [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=michid.wordpress.com&amp;blog=2538862&amp;post=252&amp;subd=michid&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>The recent discussion about the <a href="http://arxiv.org/abs/1010.5023">Yacc is dead</a> paper on <a href="http://lambda-the-ultimate.org/">Lambda the Ultimate</a> sparked my interest in regular expression derivatives. The original idea goes back to the paper <a href="http://portal.acm.org/citation.cfm?id=321249">Derivatives of Regular Expressions</a> published in 1964 (!) by Janusz A. Brzozowski. For a more modern treatment of the topic see <a href="http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.163.9032&amp;rep=rep1&amp;type=pdf">Regular-expression derivatives reexamined</a>. </p>
<p>The derivative of a set of strings with respect to a character, is the set of strings which results from removing the first character from all the strings in the set which start with that character. Let for example <img src='http://s0.wp.com/latex.php?latex=S+%3D+%5C%7Bfoo%2C+bar%2C+baz%5C%7D+&amp;bg=ffffff&amp;fg=000000&amp;s=0' alt='S = &#92;{foo, bar, baz&#92;} ' title='S = &#92;{foo, bar, baz&#92;} ' class='latex' /> then <img src='http://s0.wp.com/latex.php?latex=%5Cpartial_b+S+%3D+%5C%7Bar%2C+az%5C%7D+&amp;bg=ffffff&amp;fg=000000&amp;s=0' alt='&#92;partial_b S = &#92;{ar, az&#92;} ' title='&#92;partial_b S = &#92;{ar, az&#92;} ' class='latex' />. It turns out that regular languages are closed under derivatives. That is, any derivative of a regular language is again a regular language. Furthermore, it is possible to extend the notion of derivatives to regular expression such that given a regular expression <img src='http://s0.wp.com/latex.php?latex=r+&amp;bg=ffffff&amp;fg=000000&amp;s=0' alt='r ' title='r ' class='latex' /> which generates the language <img src='http://s0.wp.com/latex.php?latex=%5Cmathcal%7BL%7D%28r%29&amp;bg=ffffff&amp;fg=000000&amp;s=0' alt='&#92;mathcal{L}(r)' title='&#92;mathcal{L}(r)' class='latex' /> and a character <img src='http://s0.wp.com/latex.php?latex=c+&amp;bg=ffffff&amp;fg=000000&amp;s=0' alt='c ' title='c ' class='latex' />, one can derive a regular expression <img src='http://s0.wp.com/latex.php?latex=%5Cpartial_c+r&amp;bg=ffffff&amp;fg=000000&amp;s=0' alt='&#92;partial_c r' title='&#92;partial_c r' class='latex' /> such that <img src='http://s0.wp.com/latex.php?latex=%5Cmathcal%7BL%7D%28%5Cpartial_c+r%29+%3D+%5Cpartial_c%28%5Cmathcal%7BL%7D%28r%29%29&amp;bg=ffffff&amp;fg=000000&amp;s=0' alt='&#92;mathcal{L}(&#92;partial_c r) = &#92;partial_c(&#92;mathcal{L}(r))' title='&#92;mathcal{L}(&#92;partial_c r) = &#92;partial_c(&#92;mathcal{L}(r))' class='latex' />.</p>
<p>This is a key ingredient for a very elegant regular expression matching algorithm: to match a string against a regular expression repeatedly calculate the derivative of the regular expression for each characters in the string. When no character is left, check whether the last derivative accepts the empty string. If so we have a match and otherwise not. </p>
<p>The exact algorithm for finding whether a regular expression is nullable (i.e. accepts the empty string) is given in <a href="http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.163.9032&amp;rep=rep1&amp;type=pdf">Regular-expression derivatives reexamined</a> as is the algorithm for calculating derivatives of regular expressions. Below is a direct implementation of that algorithm in Scala (with a slight modification to allow for strings instead of individual characters). </p>
<p><pre class="brush: java;">
trait RegExp {
  def nullable: Boolean
  def derive(c: Char): RegExp
}

case object Empty extends RegExp {
  def nullable = false
  def derive(c: Char) = Empty
}

case object Eps extends RegExp {
  def nullable = true
  def derive(c: Char) = Empty
}

case class Str(s: String) extends RegExp {
  def nullable = s.isEmpty
  def derive(c: Char) =
    if (s.isEmpty || s.head != c) Empty
    else Str(s.tail)
}

case class Cat(r: RegExp, s: RegExp) extends RegExp {
  def nullable = r.nullable &amp;&amp; s.nullable
  def derive(c: Char) =
    if (r.nullable) Or(Cat(r.derive(c), s), s.derive(c)) 
    else Cat(r.derive(c), s)
}

case class Star(r: RegExp) extends RegExp {
  def nullable = true
  def derive(c: Char) = Cat(r.derive(c), this)
}

case class Or(r: RegExp, s: RegExp) extends RegExp {
  def nullable = r.nullable || s.nullable
  def derive(c: Char) = Or(r.derive(c), s.derive(c))
}

case class And(r: RegExp, s: RegExp) extends RegExp {
  def nullable = r.nullable &amp;&amp; s.nullable
  def derive(c: Char) = And(r.derive(c), s.derive(c))
}

case class Not(r: RegExp) extends RegExp {
  def nullable = !r.nullable
  def derive(c: Char) = Not(r.derive(c))
}
</pre></p>
<p>Having these constructors we need a way to match strings against regular expressions.</p>
<p><pre class="brush: java;">
object Matcher {
  def matches(r: RegExp, s: String): Boolean = {
    if (s.isEmpty) r.nullable
    else matches(r.derive(s.head), s.tail)
  }
}
</pre></p>
<p>Here are some <a href="http://scala.sygneca.com/patterns/pimp-my-library">pimps</a> to make usage of the regular expression constructors more convenient.</p>
<p><pre class="brush: java;">
object Pimps {
  implicit def string2RegExp(s: String) = Str(s)

  implicit def regExpOps(r: RegExp) = new {
    def | (s: RegExp) = Or(r, s)
    def &amp; (s: RegExp) = And(r, s)
    def % = Star(r)
    def %(n: Int) = rep(r, n)
    def ? = Or(Eps, r)
    def ! = Not(r)
    def ++ (s: RegExp) = Cat(r, s)
    def ~ (s: String) = Matcher.matches(r, s)
  }

  implicit def stringOps(s: String) = new {
    def | (r: RegExp) = Or(s, r)
    def | (r: String) = Or(s, r)
    def &amp; (r: RegExp) = And(s, r)
    def &amp; (r: String) = And(s, r)
    def % = Star(s)
    def % (n: Int) = rep(Str(s), n)
    def ? = Or(Eps, s)
    def ! = Not(s)
    def ++ (r: RegExp) = Cat(s, r)
    def ++ (r: String) = Cat(s, r)
    def ~ (t: String) = Matcher.matches(s, t)
  }

  def rep(r: RegExp, n: Int): RegExp =
    if (n &lt;= 0) Star(r)
    else Cat(r, rep(r, n - 1))
}
</pre></p>
<p>And finally here is how to use it:</p>
<p><pre class="brush: java;">
object Test {
  import Pimps._

  val digit = &quot;0&quot; | &quot;1&quot; | &quot;2&quot; | &quot;3&quot; | &quot;4&quot; | &quot;5&quot; | &quot;6&quot; | &quot;7&quot; | &quot;8&quot; | &quot;9&quot;
  val int = (&quot;+&quot; | &quot;-&quot;).? ++ digit.%(1)
  val real = (&quot;+&quot; | &quot;-&quot;).? ++ digit.%(1) ++ (&quot;.&quot; ++ digit.%(1)).? ++ ((&quot;e&quot; | &quot;E&quot;) ++ (&quot;+&quot; | &quot;-&quot;).? ++ digit.%(1)).?

  def main(args: Array[String]) {
    val ints = List(&quot;0&quot;, &quot;-4534&quot;, &quot;+049&quot;, &quot;99&quot;)
    val reals = List(&quot;0.9&quot;, &quot;-12.8&quot;, &quot;+91.0&quot;, &quot;9e12&quot;, &quot;+9.21E-12&quot;, &quot;-512E+01&quot;)
    val errs = List(&quot;&quot;, &quot;-&quot;, &quot;+&quot;, &quot;+-1&quot;, &quot;-+2&quot;, &quot;2-&quot;)

    ints.foreach(s =&gt; assert(int ~ s))
    reals.foreach(s =&gt; assert(!(int ~ s)))
    errs.foreach(s =&gt; assert(!(int ~ s)))

    ints.foreach(s =&gt; assert(real ~ s))
    reals.foreach(s =&gt; assert(real ~ s))
    errs.foreach(s =&gt; assert(!(real ~ s)))
}
</pre></p>
<p>Now that&#8217;s 48 + 6 + 32 = 86 lines of code for a regular expression matching library!</p>
<br />Filed under: <a href='http://michid.wordpress.com/category/uncategorized/'>Uncategorized</a> Tagged: <a href='http://michid.wordpress.com/tag/regular-expression/'>Regular Expression</a>, <a href='http://michid.wordpress.com/tag/scala/'>Scala</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/michid.wordpress.com/252/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/michid.wordpress.com/252/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/michid.wordpress.com/252/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/michid.wordpress.com/252/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/michid.wordpress.com/252/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/michid.wordpress.com/252/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/michid.wordpress.com/252/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/michid.wordpress.com/252/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/michid.wordpress.com/252/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/michid.wordpress.com/252/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/michid.wordpress.com/252/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/michid.wordpress.com/252/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/michid.wordpress.com/252/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/michid.wordpress.com/252/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=michid.wordpress.com&amp;blog=2538862&amp;post=252&amp;subd=michid&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://michid.wordpress.com/2010/12/06/regular-expression-matching-in-100-lines-of-code/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">michid</media:title>
		</media:content>
	</item>
		<item>
		<title>Generic array factory in Java: receipt for disaster</title>
		<link>http://michid.wordpress.com/2010/11/04/generic-array-factory-in-java-receipt-for-disaster/</link>
		<comments>http://michid.wordpress.com/2010/11/04/generic-array-factory-in-java-receipt-for-disaster/#comments</comments>
		<pubDate>Thu, 04 Nov 2010 23:56:58 +0000</pubDate>
		<dc:creator>michid</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Bug]]></category>
		<category><![CDATA[Java]]></category>

		<guid isPermaLink="false">http://michid.wordpress.com/?p=237</guid>
		<description><![CDATA[Let&#8217;s implement a generic factory method for arrays in Java like this: We can use this method to create any array. For example an array of strings: Now let&#8217;s add another twist: Running this code will result in a ClassCastException on the last line: Exception in thread "main" java.lang.ClassCastException: [Ljava.lang.Object; cannot be cast to [Ljava.lang.String; [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=michid.wordpress.com&amp;blog=2538862&amp;post=237&amp;subd=michid&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Let&#8217;s implement a generic factory method for arrays in Java like this:</p>
<p><pre class="brush: java;">
static &lt;T&gt; T[] createArray(T... t) {
    return t;
}
</pre></p>
<p>We can use this method to create any array. For example an array of strings:</p>
<p><pre class="brush: java;">
String[] strings = createArray(&quot;some&quot;, &quot;thing&quot;);
</pre></p>
<p>Now let&#8217;s add another twist:</p>
<p><pre class="brush: java;">
static &lt;T&gt; T[] crash(T t) {
    return createArray(t);
}

String[] outch = crash(&quot;crash&quot;, &quot;me&quot;); 
</pre></p>
<p>Running this code will result in a ClassCastException on the last line:</p>
<pre>
Exception in thread "main" java.lang.ClassCastException: [Ljava.lang.Object; cannot be cast to [Ljava.lang.String;
</pre>
<p>At first this seems strange. There is no cast anywhere here. So what is going on? Basically the Java compiler is lying at us: calling the crash method with string arguments, it tells us that we get back an array of strings. Now looking at the exception we see that this is not true. What we really get back is an array of objects!</p>
<p>Actually the Java compiler issues a warning on the createArray call in the crash method:</p>
<pre>
Type safety : A generic array of T is created for a varargs parameter
</pre>
<p>This is how it tells us about its lying: &#8220;Since I don&#8217;t know the actual type of T, I&#8217;ll just return an array of Object instead.&#8221; I thinks this is <a href="http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6227971">wrong</a>. And <a href="http://james-iry.blogspot.com/2010/05/anatomy-of-annoyance.html">others</a> seem to <a href="http://www.jroller.com/scolebourne/entry/generics_bashing_your_head_against">think</a> along the same lines. </p>
<br />Filed under: <a href='http://michid.wordpress.com/category/uncategorized/'>Uncategorized</a> Tagged: <a href='http://michid.wordpress.com/tag/bug/'>Bug</a>, <a href='http://michid.wordpress.com/tag/java/'>Java</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/michid.wordpress.com/237/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/michid.wordpress.com/237/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/michid.wordpress.com/237/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/michid.wordpress.com/237/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/michid.wordpress.com/237/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/michid.wordpress.com/237/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/michid.wordpress.com/237/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/michid.wordpress.com/237/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/michid.wordpress.com/237/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/michid.wordpress.com/237/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/michid.wordpress.com/237/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/michid.wordpress.com/237/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/michid.wordpress.com/237/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/michid.wordpress.com/237/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=michid.wordpress.com&amp;blog=2538862&amp;post=237&amp;subd=michid&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://michid.wordpress.com/2010/11/04/generic-array-factory-in-java-receipt-for-disaster/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">michid</media:title>
		</media:content>
	</item>
		<item>
		<title>So Scala is too complex?</title>
		<link>http://michid.wordpress.com/2010/08/24/so-scala-is-too-complex/</link>
		<comments>http://michid.wordpress.com/2010/08/24/so-scala-is-too-complex/#comments</comments>
		<pubDate>Tue, 24 Aug 2010 21:04:04 +0000</pubDate>
		<dc:creator>michid</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Scala]]></category>

		<guid isPermaLink="false">http://michid.wordpress.com/?p=230</guid>
		<description><![CDATA[There is currently lots of talk about Scala being to complex. Instead of more arguing I implemented the same bit of functionality in Scala and in Java and let everyone decide for themselves. There is some nice example code in the manual to the The Scala 2.8 Collections API which partitions a list of persons [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=michid.wordpress.com&amp;blog=2538862&amp;post=230&amp;subd=michid&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>There is currently <a href="http://warpedjavaguy.wordpress.com/2010/08/02/the-scala-is-too-complex-conspiracy-1/">lots of talk</a> about <a href="http://www.scala-lang.org/">Scala</a> being to complex. Instead of more arguing I implemented the same bit of functionality in Scala and in Java and let everyone decide for themselves. </p>
<p>There is some nice example code in the manual to the <a href="http://lampwww.epfl.ch/~odersky/whatsnew/collections-api/collections.html">The Scala 2.8 Collections API</a> which partitions a list of persons into two lists of minors and majors. Below are the fleshed out implementations in Scala and Java.</p>
<p>First Scala:<br />
<pre class="brush: java;">
object ScalaMain {
  case class Person(name: String, age: Int)
    
  val persons = List(
    Person(&quot;Boris&quot;, 40),
    Person(&quot;Betty&quot;, 32),
    Person(&quot;Bambi&quot;, 17))

  val (minors, majors) = persons.partition(_.age &lt;= 18) 
   
  def main(args: Array[String]) = {
    println (minors.mkString(&quot;, &quot;))
    println (majors.mkString(&quot;, &quot;))
  }
}
</pre></p>
<p>And now Java:<br />
<pre class="brush: java;">
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;

class Person {
    private final String name;
    private final int age;

    public Person(String name, int age) {
        super();
        this.name = name;
        this.age = age;
    }

    public String getName() {
        return name;
    }

    public int getAge() {
        return age;
    }

    @Override
    public boolean equals(Object other) {
        if (this == other) {
            return true;
        }
        else if (other instanceof Person) {
            Person p = (Person) other;
            return name == null ? p.name == null : name.equals(p.name)
                    &amp;&amp; age == p.age;

        }
        else {
            return false;
        }
    }

    @Override
    public int hashCode() {
        int h = name == null ? 0 : name.hashCode();
        return 39*h + age;
    }

    @Override
    public String toString() {
        return new StringBuilder(&quot;Person(&quot;)
            .append(name).append(&quot;,&quot;)
            .append(age).append(&quot;)&quot;).toString();
    }
}

public class JavaMain {

    private final static List&lt;Person&gt; persons = Arrays.asList(
        new Person(&quot;Boris&quot;, 40),
        new Person(&quot;Betty&quot;, 32),
        new Person(&quot;Bamby&quot;, 17));

    private static List&lt;Person&gt; minors = new ArrayList&lt;Person&gt;();
    private static List&lt;Person&gt; majors = new ArrayList&lt;Person&gt;();

    public static void main(String[] args) {
        partition(persons, minors, majors);
        System.out.println(mkString(minors, &quot;,&quot;));
        System.out.println(mkString(majors, &quot;,&quot;));
    }

    private static void partition(List&lt;? extends Person&gt; persons,
            List&lt;? super Person&gt; minors, List&lt;? super Person&gt; majors) {

        for (Person p : persons) {
            if (p.getAge() &lt;= 18) minors.add(p);
            else majors.add(p);
        }
    }

    private static &lt;T&gt; String mkString(List&lt;T&gt; list, String separator) {
        StringBuilder s = new StringBuilder();
        Iterator&lt;T&gt; it = list.iterator();
        if (it.hasNext()) {
            s.append(it.next());
        }
        while (it.hasNext()) {
            s.append(separator).append(it.next());
        }
        return s.toString();
    }

}
</pre></p>
<p>Impressive huh? And the Java version is not even entirely correct since its equals() method might not cope correctly with super classes of Person.</p>
<br />Filed under: <a href='http://michid.wordpress.com/category/uncategorized/'>Uncategorized</a> Tagged: <a href='http://michid.wordpress.com/tag/java/'>Java</a>, <a href='http://michid.wordpress.com/tag/scala/'>Scala</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/michid.wordpress.com/230/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/michid.wordpress.com/230/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/michid.wordpress.com/230/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/michid.wordpress.com/230/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/michid.wordpress.com/230/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/michid.wordpress.com/230/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/michid.wordpress.com/230/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/michid.wordpress.com/230/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/michid.wordpress.com/230/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/michid.wordpress.com/230/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/michid.wordpress.com/230/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/michid.wordpress.com/230/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/michid.wordpress.com/230/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/michid.wordpress.com/230/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=michid.wordpress.com&amp;blog=2538862&amp;post=230&amp;subd=michid&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://michid.wordpress.com/2010/08/24/so-scala-is-too-complex/feed/</wfw:commentRss>
		<slash:comments>107</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">michid</media:title>
		</media:content>
	</item>
		<item>
		<title>Type Level Programming: Equality</title>
		<link>http://michid.wordpress.com/2010/06/18/type-level-programming-equality/</link>
		<comments>http://michid.wordpress.com/2010/06/18/type-level-programming-equality/#comments</comments>
		<pubDate>Fri, 18 Jun 2010 16:13:53 +0000</pubDate>
		<dc:creator>michid</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Meta-Programming]]></category>
		<category><![CDATA[Scala]]></category>

		<guid isPermaLink="false">http://michid.wordpress.com/?p=221</guid>
		<description><![CDATA[Apocalisp has a great series on Type Level Programming with Scala. At some point the question came up whether it is possible to determine equality of types at run time by having the compiler generate types representing true and false respectively. Here is what I came up with. Admittedly this is very hacky. For the [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=michid.wordpress.com&amp;blog=2538862&amp;post=221&amp;subd=michid&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><a href="http://apocalisp.wordpress.com/">Apocalisp</a> has a great series on <a href="http://michid.wordpress.com/2010/01/29/scala-type-level-encoding-of-the-ski-calculus/">Type</a> <a href="http://michid.wordpress.com/2008/10/29/meta-programming-with-scala-conditional-compilation-and-loop-unrolling/">Level</a> <a href="http://michid.wordpress.com/2008/08/27/meta-programming-with-scala-part-iii-partial-function-application/">Programming</a> <a href="http://michid.wordpress.com/2008/07/30/meta-programming-with-scala-part-ii-multiplication/">with</a> <a href="http://michid.wordpress.com/2008/04/18/meta-programming-with-scala-part-i-addition/">Scala</a>. At <a href="http://apocalisp.wordpress.com/2010/06/10/type-level-programming-in-scala-part-2-implicitly-and/">some point</a> the question came up whether it is possible to determine equality of types at run time by having the compiler generate types representing <em>true</em> and <em>false</em> respectively. Here is what I came up with. </p>
<p><pre class="brush: java;">
trait True { type t = True }
trait False { type t = False }

case class Equality[A] {
  def check(x: A)(implicit t: True) = t
  def check[B](x: B)(implicit f: False) = f
}
object Equality {
  def witness[T] = null.asInstanceOf[T]
  implicit val t: True = null
  implicit val f: False = null
}

// Usage:
import Equality._
    
val test1 = Equality[List[Boolean]] check witness[List[Boolean]]
implicitly[test1.t =:= True]
// Does not compile since tt is True
// implicitly[test1.t =:= False]  

val test2 = Equality[Nothing] check witness[AnyRef]
// Does not compile since ft is False
// implicitly[test2.t =:= True]  
implicitly[test2.t =:= False]
</pre></p>
<p>Admittedly this is very hacky. For the time being I don&#8217;t see how to further clean this up. Anyone?</p>
<br />Filed under: <a href='http://michid.wordpress.com/category/uncategorized/'>Uncategorized</a> Tagged: <a href='http://michid.wordpress.com/tag/meta-programming/'>Meta-Programming</a>, <a href='http://michid.wordpress.com/tag/scala/'>Scala</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/michid.wordpress.com/221/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/michid.wordpress.com/221/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/michid.wordpress.com/221/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/michid.wordpress.com/221/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/michid.wordpress.com/221/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/michid.wordpress.com/221/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/michid.wordpress.com/221/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/michid.wordpress.com/221/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/michid.wordpress.com/221/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/michid.wordpress.com/221/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/michid.wordpress.com/221/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/michid.wordpress.com/221/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/michid.wordpress.com/221/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/michid.wordpress.com/221/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=michid.wordpress.com&amp;blog=2538862&amp;post=221&amp;subd=michid&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://michid.wordpress.com/2010/06/18/type-level-programming-equality/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">michid</media:title>
		</media:content>
	</item>
		<item>
		<title>Working around type erasure ambiguities (Scala)</title>
		<link>http://michid.wordpress.com/2010/06/14/working-around-type-erasure-ambiguities-scala/</link>
		<comments>http://michid.wordpress.com/2010/06/14/working-around-type-erasure-ambiguities-scala/#comments</comments>
		<pubDate>Mon, 14 Jun 2010 21:33:21 +0000</pubDate>
		<dc:creator>michid</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Puzzle]]></category>
		<category><![CDATA[Scala]]></category>

		<guid isPermaLink="false">http://michid.wordpress.com/?p=214</guid>
		<description><![CDATA[In my previous post I showed a workaround for the type erasure ambiguity problem in Java. The solution uses vararg parameters for disambiguation. As Paul Phillips points out in his comment, this solution doesn&#8217;t directly port over to Scala. Java uses Array to pass varargs, Scala uses Seq. Unlike Array, Seq is not reified so [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=michid.wordpress.com&amp;blog=2538862&amp;post=214&amp;subd=michid&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>In my <a href="http://michid.wordpress.com/2010/05/30/working-around-type-erasure-ambiguities/">previous post</a> I showed a workaround for the type erasure ambiguity problem in Java. The solution uses vararg parameters for disambiguation. As <a href="http://michid.wordpress.com/2010/05/30/working-around-type-erasure-ambiguities/#comment-456">Paul Phillips</a> points out in his comment, this solution doesn&#8217;t directly port over to Scala. Java uses Array to pass varargs, Scala uses Seq. Unlike Array, Seq is not reified so Seq[String] and Seq[Int] again erase to the same type putting us back to square one. </p>
<p>However, there is another way to add disambiguation parameters to the methods: implicits! Here is how:<br />
<pre class="brush: java;">
implicit val x: Int = 0
def foo(a: List[Int])(implicit ignore: Int) { }
  
implicit val y = &quot;&quot;
def foo(a: List[String])(implicit ignore: String) { }

foo(1::2::Nil)
foo(&quot;a&quot;::&quot;b&quot;::Nil)
</pre></p>
<br />Filed under: <a href='http://michid.wordpress.com/category/uncategorized/'>Uncategorized</a> Tagged: <a href='http://michid.wordpress.com/tag/puzzle/'>Puzzle</a>, <a href='http://michid.wordpress.com/tag/scala/'>Scala</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/michid.wordpress.com/214/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/michid.wordpress.com/214/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/michid.wordpress.com/214/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/michid.wordpress.com/214/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/michid.wordpress.com/214/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/michid.wordpress.com/214/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/michid.wordpress.com/214/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/michid.wordpress.com/214/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/michid.wordpress.com/214/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/michid.wordpress.com/214/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/michid.wordpress.com/214/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/michid.wordpress.com/214/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/michid.wordpress.com/214/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/michid.wordpress.com/214/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=michid.wordpress.com&amp;blog=2538862&amp;post=214&amp;subd=michid&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://michid.wordpress.com/2010/06/14/working-around-type-erasure-ambiguities-scala/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">michid</media:title>
		</media:content>
	</item>
		<item>
		<title>Working around type erasure ambiguities</title>
		<link>http://michid.wordpress.com/2010/05/30/working-around-type-erasure-ambiguities/</link>
		<comments>http://michid.wordpress.com/2010/05/30/working-around-type-erasure-ambiguities/#comments</comments>
		<pubDate>Sun, 30 May 2010 15:05:46 +0000</pubDate>
		<dc:creator>michid</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Puzzle]]></category>
		<category><![CDATA[Scala]]></category>

		<guid isPermaLink="false">http://michid.wordpress.com/?p=210</guid>
		<description><![CDATA[In an earlier post I already showed how to work around ambiguous method overloads resulting from type erasure. In a nut shell the following code wont compile since both overloaded methods foo erase to the same type. Scala: Java: It turns out that there is a simple though somewhat hacky way to work around this [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=michid.wordpress.com&amp;blog=2538862&amp;post=210&amp;subd=michid&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>In an earlier <a href="http://michid.wordpress.com/2008/01/18/implicit-double-dispatch/">post</a> I already showed how to work around ambiguous method overloads resulting from type erasure. In a nut shell the following code wont compile since both overloaded methods <em>foo</em> erase to the same type. </p>
<p>Scala:<br />
<pre class="brush: java;">
def foo(ints: List[Int]) {}
def foo(strings: List[String]) {}
</pre></p>
<p>Java:<br />
<pre class="brush: java;">
void foo(List&lt;Integer&gt; ints) {}
void foo(List&lt;String&gt; strings) {}
</pre></p>
<p>It turns out that there is a simple though somewhat hacky way to work around this limitations: in order to make the ambiguity go away, we need to change the signature of <em>foo</em> in such a way that 1) the erasure of the <em>foo</em> methods are different and 2) the call site is not affected. </p>
<p>Here is a solution for Java:</p>
<p><pre class="brush: java;">
void foo(List&lt;Integer&gt; ints, Integer... ignore) {}
void foo(List&lt;String&gt; strings, String... ignore) {}
</pre></p>
<p>We can now call <em>foo</em> passing either a list of ints or a list of strings without ambiguity: </p>
<p><pre class="brush: java;">
foo(new ArrayList&lt;Integer&gt;());
foo(new ArrayList&lt;String&gt;());
</pre></p>
<p>This doesn&#8217;t directly port over to Scala (why?). However, there is a similar hack for Scala. I leave this as a puzzle for a couple of days before I post my solution. </p>
<br />Filed under: <a href='http://michid.wordpress.com/category/uncategorized/'>Uncategorized</a> Tagged: <a href='http://michid.wordpress.com/tag/java/'>Java</a>, <a href='http://michid.wordpress.com/tag/puzzle/'>Puzzle</a>, <a href='http://michid.wordpress.com/tag/scala/'>Scala</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/michid.wordpress.com/210/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/michid.wordpress.com/210/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/michid.wordpress.com/210/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/michid.wordpress.com/210/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/michid.wordpress.com/210/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/michid.wordpress.com/210/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/michid.wordpress.com/210/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/michid.wordpress.com/210/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/michid.wordpress.com/210/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/michid.wordpress.com/210/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/michid.wordpress.com/210/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/michid.wordpress.com/210/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/michid.wordpress.com/210/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/michid.wordpress.com/210/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=michid.wordpress.com&amp;blog=2538862&amp;post=210&amp;subd=michid&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://michid.wordpress.com/2010/05/30/working-around-type-erasure-ambiguities/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">michid</media:title>
		</media:content>
	</item>
		<item>
		<title>[ANN] Talking at Scala Days 2010 in Lausanne next Thursday</title>
		<link>http://michid.wordpress.com/2010/04/11/ann-talking-at-scala-days-2010-in-lausanne-next-thursday/</link>
		<comments>http://michid.wordpress.com/2010/04/11/ann-talking-at-scala-days-2010-in-lausanne-next-thursday/#comments</comments>
		<pubDate>Sun, 11 Apr 2010 20:05:17 +0000</pubDate>
		<dc:creator>michid</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Conference]]></category>
		<category><![CDATA[Scala]]></category>

		<guid isPermaLink="false">http://michid.wordpress.com/?p=206</guid>
		<description><![CDATA[I&#8217;ll be talking at Scala Days 2010 in Lausanne on April 15th about the Scala scripting engine for Apache Sling. While my talk at Jazoon 09 was mainly about using Scala from Sling, this session will be more focused on internals of the Scala scripting engine. Unfortunately (or fortunately depending on the point of view) [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=michid.wordpress.com&amp;blog=2538862&amp;post=206&amp;subd=michid&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ll be talking at <a href="http://days2010.scala-lang.org/">Scala Days 2010</a> in Lausanne on April 15th about the Scala scripting engine for <a href="http://sling.apache.org/">Apache Sling</a>. While my talk at <a href="http://people.apache.org/~mduerig/scala4sling/">Jazoon 09</a> was mainly about using Scala from Sling, <a href="http://days2010.scala-lang.org/node/50">this session</a> will be more focused on internals of the Scala scripting engine. </p>
<p>Unfortunately (or fortunately depending on the point of view) the conference is sold out already. Watch my <a href="http://people.apache.org/~mduerig/scala4scripting/">Scala for scripting</a> page for the session slides and other upcoming support material.</p>
<br />Filed under: <a href='http://michid.wordpress.com/category/uncategorized/'>Uncategorized</a> Tagged: <a href='http://michid.wordpress.com/tag/conference/'>Conference</a>, <a href='http://michid.wordpress.com/tag/scala/'>Scala</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/michid.wordpress.com/206/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/michid.wordpress.com/206/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/michid.wordpress.com/206/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/michid.wordpress.com/206/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/michid.wordpress.com/206/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/michid.wordpress.com/206/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/michid.wordpress.com/206/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/michid.wordpress.com/206/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/michid.wordpress.com/206/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/michid.wordpress.com/206/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/michid.wordpress.com/206/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/michid.wordpress.com/206/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/michid.wordpress.com/206/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/michid.wordpress.com/206/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=michid.wordpress.com&amp;blog=2538862&amp;post=206&amp;subd=michid&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://michid.wordpress.com/2010/04/11/ann-talking-at-scala-days-2010-in-lausanne-next-thursday/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">michid</media:title>
		</media:content>
	</item>
		<item>
		<title>Scala type level encoding of the SKI calculus</title>
		<link>http://michid.wordpress.com/2010/01/29/scala-type-level-encoding-of-the-ski-calculus/</link>
		<comments>http://michid.wordpress.com/2010/01/29/scala-type-level-encoding-of-the-ski-calculus/#comments</comments>
		<pubDate>Fri, 29 Jan 2010 17:58:41 +0000</pubDate>
		<dc:creator>michid</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Meta-Programming]]></category>
		<category><![CDATA[Scala]]></category>

		<guid isPermaLink="false">http://michid.wordpress.com/?p=192</guid>
		<description><![CDATA[In one of my posts on type level meta programming in Scala the question of Turing completeness came up already. The question is whether Scala&#8217;s type system can be used to force the Scala compiler to carry out any calculation which a Turing machine is capable of. Various of my older posts show how Scala&#8217;s [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=michid.wordpress.com&amp;blog=2538862&amp;post=192&amp;subd=michid&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>In one of my <a href="http://michid.wordpress.com/2008/10/29/meta-programming-with-scala-conditional-compilation-and-loop-unrolling/">posts</a> on type level meta programming in Scala the question of <a href="http://en.wikipedia.org/wiki/Turing_complete">Turing completeness</a> came up already. The question is whether Scala&#8217;s type system can be used to force the Scala compiler to carry out any calculation which a Turing machine is capable of. Various of my older posts show how Scala&#8217;s type system can be used to encode <a href="http://michid.wordpress.com/2008/04/18/meta-programming-with-scala-part-i-addition/">addition</a> and <a href="http://michid.wordpress.com/2008/08/27/meta-programming-with-scala-part-iii-partial-function-application/">multiplication</a> on natural numbers and how to encode <a href="http://michid.wordpress.com/2008/10/29/meta-programming-with-scala-conditional-compilation-and-loop-unrolling/">conditions and bounded loops</a>. </p>
<p>Motivated by the blog post <a href="http://apocalisp.wordpress.com/2009/09/02/more-scala-typehackery/">More Scala Typehackery</a> which shows how to encode a version of the <a href="http://en.wikipedia.org/wiki/Lambda_calculus">Lambda calculus</a> which is limited to abstraction over a single variable in Scala&#8217;s type system I set out to further explore the topic. </p>
<p><H3>The SKI combinator calculus</H3><br />
Looking for a calculus which is relatively small, easily encoded in Scala&#8217;s type system and known to be Turing complete I came across the <a href="http://en.wikipedia.org/wiki/SKI_combinator_calculus">SKI combinator calculus</a>. The SKI combinators are defined as follows:</p>
<p>  <img src='http://s0.wp.com/latex.php?latex=Ix+%5Crightarrow+x+&amp;bg=ffffff&amp;fg=000000&amp;s=0' alt='Ix &#92;rightarrow x ' title='Ix &#92;rightarrow x ' class='latex' />,<br />
  <img src='http://s0.wp.com/latex.php?latex=Kxy+%5Crightarrow+x+&amp;bg=ffffff&amp;fg=000000&amp;s=0' alt='Kxy &#92;rightarrow x ' title='Kxy &#92;rightarrow x ' class='latex' />,<br />
  <img src='http://s0.wp.com/latex.php?latex=Sxyz+%5Crightarrow+xz%28yz%29+&amp;bg=ffffff&amp;fg=000000&amp;s=0' alt='Sxyz &#92;rightarrow xz(yz) ' title='Sxyz &#92;rightarrow xz(yz) ' class='latex' />.</p>
<p>They can be used to encode arbitrary calculations. For example reversal of arguments. Let <img src='http://s0.wp.com/latex.php?latex=R+%5Cequiv+S%28K%28SI%29%29K+&amp;bg=ffffff&amp;fg=000000&amp;s=0' alt='R &#92;equiv S(K(SI))K ' title='R &#92;equiv S(K(SI))K ' class='latex' />. Then </p>
<p>  <img src='http://s0.wp.com/latex.php?latex=R+x+y+%5Cequiv+&amp;bg=ffffff&amp;fg=000000&amp;s=0' alt='R x y &#92;equiv ' title='R x y &#92;equiv ' class='latex' /><br />
  <img src='http://s0.wp.com/latex.php?latex=S%28K%28SI%29%29K+x+y+%5Crightarrow+&amp;bg=ffffff&amp;fg=000000&amp;s=0' alt='S(K(SI))K x y &#92;rightarrow ' title='S(K(SI))K x y &#92;rightarrow ' class='latex' /><br />
  <img src='http://s0.wp.com/latex.php?latex=K%28SI%29x%28Kx%29y+%5Crightarrow+&amp;bg=ffffff&amp;fg=000000&amp;s=0' alt='K(SI)x(Kx)y &#92;rightarrow ' title='K(SI)x(Kx)y &#92;rightarrow ' class='latex' /><br />
  <img src='http://s0.wp.com/latex.php?latex=SI%28Kx%29y+%5Crightarrow+&amp;bg=ffffff&amp;fg=000000&amp;s=0' alt='SI(Kx)y &#92;rightarrow ' title='SI(Kx)y &#92;rightarrow ' class='latex' /><br />
  <img src='http://s0.wp.com/latex.php?latex=Iy%28Kxy%29+%5Crightarrow+&amp;bg=ffffff&amp;fg=000000&amp;s=0' alt='Iy(Kxy) &#92;rightarrow ' title='Iy(Kxy) &#92;rightarrow ' class='latex' /><br />
  <img src='http://s0.wp.com/latex.php?latex=Iyx+%5Crightarrow+yx+&amp;bg=ffffff&amp;fg=000000&amp;s=0' alt='Iyx &#92;rightarrow yx ' title='Iyx &#92;rightarrow yx ' class='latex' />.</p>
<p>Self application is used to find <a href="http://en.wikipedia.org/wiki/Fixed_point_combinator">fixed points</a>. Let <img src='http://s0.wp.com/latex.php?latex=%5Cbeta+%5Cequiv+S%28K%5Calpha%29%28SII%29+&amp;bg=ffffff&amp;fg=000000&amp;s=0' alt='&#92;beta &#92;equiv S(K&#92;alpha)(SII) ' title='&#92;beta &#92;equiv S(K&#92;alpha)(SII) ' class='latex' /> for some combinator <img src='http://s0.wp.com/latex.php?latex=%5Calpha+&amp;bg=ffffff&amp;fg=000000&amp;s=0' alt='&#92;alpha ' title='&#92;alpha ' class='latex' />. Then <img src='http://s0.wp.com/latex.php?latex=%5Cbeta%5Cbeta+%5Crightarrow+%5Calpha%28%5Cbeta+%5Cbeta%29+&amp;bg=ffffff&amp;fg=000000&amp;s=0' alt='&#92;beta&#92;beta &#92;rightarrow &#92;alpha(&#92;beta &#92;beta) ' title='&#92;beta&#92;beta &#92;rightarrow &#92;alpha(&#92;beta &#92;beta) ' class='latex' />. That is, <img src='http://s0.wp.com/latex.php?latex=%5Cbeta%5Cbeta&amp;bg=ffffff&amp;fg=000000&amp;s=0' alt='&#92;beta&#92;beta' title='&#92;beta&#92;beta' class='latex' /> is a fixed point of <img src='http://s0.wp.com/latex.php?latex=%5Calpha+&amp;bg=ffffff&amp;fg=000000&amp;s=0' alt='&#92;alpha ' title='&#92;alpha ' class='latex' />. This can be used to achieve recursion. Let <img src='http://s0.wp.com/latex.php?latex=R+&amp;bg=ffffff&amp;fg=000000&amp;s=0' alt='R ' title='R ' class='latex' /> be the reversal combinator from above. Further define </p>
<p>  <img src='http://s0.wp.com/latex.php?latex=A_0+x+%5Cequiv+c+&amp;bg=ffffff&amp;fg=000000&amp;s=0' alt='A_0 x &#92;equiv c ' title='A_0 x &#92;equiv c ' class='latex' /> for some combinator <img src='http://s0.wp.com/latex.php?latex=c+&amp;bg=ffffff&amp;fg=000000&amp;s=0' alt='c ' title='c ' class='latex' /> and<br />
  <img src='http://s0.wp.com/latex.php?latex=A_n+x+%5Cequiv+x+A_%7Bn-1%7D+&amp;bg=ffffff&amp;fg=000000&amp;s=0' alt='A_n x &#92;equiv x A_{n-1} ' title='A_n x &#92;equiv x A_{n-1} ' class='latex' />.</p>
<p>That is, combinator <img src='http://s0.wp.com/latex.php?latex=A_n&amp;bg=ffffff&amp;fg=000000&amp;s=0' alt='A_n' title='A_n' class='latex' /> is the combinator obtained by applying its argument to the combinator <img src='http://s0.wp.com/latex.php?latex=A_%7Bn-1%7D&amp;bg=ffffff&amp;fg=000000&amp;s=0' alt='A_{n-1}' title='A_{n-1}' class='latex' />. (There is a bit of cheating here: I should actually show that such combinators exist. However since the SKI calculus is Turing complete, I take this for granted.) Now let <img src='http://s0.wp.com/latex.php?latex=%5Calpha+&amp;bg=ffffff&amp;fg=000000&amp;s=0' alt='&#92;alpha ' title='&#92;alpha ' class='latex' /> be <img src='http://s0.wp.com/latex.php?latex=R&amp;bg=ffffff&amp;fg=000000&amp;s=0' alt='R' title='R' class='latex' /> in <img src='http://s0.wp.com/latex.php?latex=%5Cbeta+&amp;bg=ffffff&amp;fg=000000&amp;s=0' alt='&#92;beta ' title='&#92;beta ' class='latex' /> from above (That is we have <img src='http://s0.wp.com/latex.php?latex=%5Cbeta+%5Cequiv+S%28KR%29%28SII%29&amp;bg=ffffff&amp;fg=000000&amp;s=0' alt='&#92;beta &#92;equiv S(KR)(SII)' title='&#92;beta &#92;equiv S(KR)(SII)' class='latex' /> now). Then</p>
<p>  <img src='http://s0.wp.com/latex.php?latex=%5Cbeta%5Cbeta+A_0+%5Crightarrow+c&amp;bg=ffffff&amp;fg=000000&amp;s=0' alt='&#92;beta&#92;beta A_0 &#92;rightarrow c' title='&#92;beta&#92;beta A_0 &#92;rightarrow c' class='latex' /> </p>
<p>and by induction</p>
<p>  <img src='http://s0.wp.com/latex.php?latex=%5Cbeta%5Cbeta+A_n+%5Crightarrow+%5Cbeta%5Cbeta+A_%7Bn-1%7D+%5Crightarrow+c&amp;bg=ffffff&amp;fg=000000&amp;s=0' alt='&#92;beta&#92;beta A_n &#92;rightarrow &#92;beta&#92;beta A_{n-1} &#92;rightarrow c' title='&#92;beta&#92;beta A_n &#92;rightarrow &#92;beta&#92;beta A_{n-1} &#92;rightarrow c' class='latex' />.</p>
<p><H3>Type level SKI in Scala</H3><br />
Encoding the SKI combinator calculus in Scala&#8217;s type system seems not too difficult at first. It turns out however that some care has to be taken regarding the order of evaluation. To guarantee that for all terms which have a normal form, that normal form is actually found, a lazy evaluation order has to be employed. </p>
<p>Here is a Scala type level encoding of the SKI calculus:</p>
<p><pre class="brush: java;">
trait Term {
  type ap[x &lt;: Term] &lt;: Term
  type eval &lt;: Term
}
  
// The S combinator
trait S extends Term {
  type ap[x &lt;: Term] = S1[x] 
  type eval = S
}
trait S1[x &lt;: Term] extends Term {
  type ap[y &lt;: Term] = S2[x, y]
  type eval = S1[x]
}
trait S2[x &lt;: Term, y &lt;: Term] extends Term {
  type ap[z &lt;: Term] = S3[x, y, z]
  type eval = S2[x, y]
}
trait S3[x &lt;: Term, y &lt;: Term, z &lt;: Term] extends Term {
  type ap[v &lt;: Term] = eval#ap[v]
  type eval = x#ap[z]#ap[y#ap[z]]#eval
}

// The K combinator
trait K extends Term {
  type ap[x &lt;: Term] = K1[x]
  type eval = K
}
trait K1[x &lt;: Term] extends Term {
  type ap[y &lt;: Term] = K2[x, y]
  type eval = K1[x]
}
trait K2[x &lt;: Term, y &lt;: Term] extends Term {
  type ap[z &lt;: Term] = eval#ap[z]
  type eval = x#eval
}
  
// The I combinator
trait I extends Term {
  type ap[x &lt;: Term] = I1[x]
  type eval = I
}
trait I1[x &lt;: Term] extends Term {
  type ap[y &lt;: Term] = eval#ap[y]
  type eval = x#eval
}
</pre></p>
<p>Further lets define some constants to act upon. These are used to test whether the calculus actually works.</p>
<p><pre class="brush: java;">
trait c extends Term {
  type ap[x &lt;: Term] = c
  type eval = c
}
trait d extends Term {
  type ap[x &lt;: Term] = d
  type eval = d
}
trait e extends Term {
  type ap[x &lt;: Term] = e
  type eval = e
}
</pre></p>
<p>Eventually the following definition of <em>Equals</em> lets us check types for equality:</p>
<p><pre class="brush: java;">
case class Equals[A &gt;: B &lt;:B , B]()

Equals[Int, Int]     // compiles fine
Equals[String, Int] // won't compile
</pre></p>
<p>Now lets see whether we can evaluate some combinators.</p>
<p><pre class="brush: java;">
  // Ic -&gt; c
  Equals[I#ap[c]#eval, c]
  
  // Kcd -&gt; c
  Equals[K#ap[c]#ap[d]#eval, c]

  // KKcde -&gt; d
  Equals[K#ap[K]#ap[c]#ap[d]#ap[e]#eval, d]
  
  // SIIIc -&gt; Ic
  Equals[S#ap[I]#ap[I]#ap[I]#ap[c]#eval, c]

  // SKKc -&gt; Ic
  Equals[S#ap[K]#ap[K]#ap[c]#eval, c]

  // SIIKc -&gt; KKc
  Equals[S#ap[I]#ap[I]#ap[K]#ap[c]#eval, K#ap[K]#ap[c]#eval]

  // SIKKc -&gt; K(KK)c
  Equals[S#ap[I]#ap[K]#ap[K]#ap[c]#eval, K#ap[K#ap[K]]#ap[c]#eval]

  // SIKIc -&gt; KIc
  Equals[S#ap[I]#ap[K]#ap[I]#ap[c]#eval, K#ap[I]#ap[c]#eval]

  // SKIc -&gt; Ic
  Equals[S#ap[K]#ap[I]#ap[c]#eval, c]
  
  // R = S(K(SI))K  (reverse)
  type R = S#ap[K#ap[S#ap[I]]]#ap[K]
  Equals[R#ap[c]#ap[d]#eval, d#ap[c]#eval]
</pre></p>
<p>Finally lets check whether we can do recursion using the fixed point operator from above. First lets define <img src='http://s0.wp.com/latex.php?latex=%5Cbeta+&amp;bg=ffffff&amp;fg=000000&amp;s=0' alt='&#92;beta ' title='&#92;beta ' class='latex' />.</p>
<p><pre class="brush: java;">
  // b(a) = S(Ka)(SII)
  type b[a &lt;: Term] = S#ap[K#ap[a]]#ap[S#ap[I]#ap[I]]
</pre></p>
<p>Further lets define some of the <img src='http://s0.wp.com/latex.php?latex=A_n&amp;bg=ffffff&amp;fg=000000&amp;s=0' alt='A_n' title='A_n' class='latex' />s from above.</p>
<p><pre class="brush: java;">
trait A0 extends Term {
  type ap[x &lt;: Term] = c
  type eval = A0
}
trait A1 extends Term {
  type ap[x &lt;: Term] = x#ap[A0]#eval
  type eval = A1
}
trait A2 extends Term {
  type ap[x &lt;: Term] = x#ap[A1]#eval
  type eval = A2
}
</pre></p>
<p>Now we can do iteration on the type level using a fixed point combinator:</p>
<p><pre class="brush: java;">
  // Single iteration
  type NN1 = b[R]#ap[b[R]]#ap[A0]
  Equals[NN1#eval, c]

  // Double iteration
  type NN2 = b[R]#ap[b[R]]#ap[A1]
  Equals[NN2#eval, c]

  // Triple iteration
  type NN3 = b[R]#ap[b[R]]#ap[A2]
  Equals[NN3#eval, c]
</pre></p>
<p>Finally lets check whether we can do &#8216;unbounded&#8217; iteration. </p>
<p><pre class="brush: java;">
trait An extends Term {
  type ap[x &lt;: Term] = x#ap[An]#eval
  type eval = An
}
// Infinite iteration: Smashes scalac's stack
  type NNn = b[R]#ap[b[R]]#ap[An]
  Equals[NNn#eval, c]
</pre></p>
<p>Well, we can <img src='http://s1.wp.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>
<pre>
$ scalac SKI.scala
Exception in thread "main" java.lang.StackOverflowError
        at scala.tools.nsc.symtab.Types$SubstMap.apply(Types.scala:3165)
        at scala.tools.nsc.symtab.Types$SubstMap.apply(Types.scala:3136)
        at scala.tools.nsc.symtab.Types$TypeMap.mapOver(Types.scala:2735)
</pre>
<br />Filed under: <a href='http://michid.wordpress.com/category/uncategorized/'>Uncategorized</a> Tagged: <a href='http://michid.wordpress.com/tag/meta-programming/'>Meta-Programming</a>, <a href='http://michid.wordpress.com/tag/scala/'>Scala</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/michid.wordpress.com/192/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/michid.wordpress.com/192/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/michid.wordpress.com/192/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/michid.wordpress.com/192/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/michid.wordpress.com/192/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/michid.wordpress.com/192/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/michid.wordpress.com/192/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/michid.wordpress.com/192/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/michid.wordpress.com/192/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/michid.wordpress.com/192/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/michid.wordpress.com/192/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/michid.wordpress.com/192/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/michid.wordpress.com/192/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/michid.wordpress.com/192/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=michid.wordpress.com&amp;blog=2538862&amp;post=192&amp;subd=michid&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://michid.wordpress.com/2010/01/29/scala-type-level-encoding-of-the-ski-calculus/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">michid</media:title>
		</media:content>
	</item>
	</channel>
</rss>
