<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	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>Comments on: Meta-Programming with Scala Part II: Multiplication</title>
	<atom:link href="http://michid.wordpress.com/2008/07/30/meta-programming-with-scala-part-ii-multiplication/feed/" rel="self" type="application/rss+xml" />
	<link>http://michid.wordpress.com/2008/07/30/meta-programming-with-scala-part-ii-multiplication/</link>
	<description>Hacking Scala</description>
	<lastBuildDate>Sun, 30 Aug 2009 19:20:59 +0000</lastBuildDate>
	<generator>http://wordpress.com/</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Meta-Programming with Scala: Conditional Compilation and Loop Unrolling &#171; Michid&#8217;s Weblog</title>
		<link>http://michid.wordpress.com/2008/07/30/meta-programming-with-scala-part-ii-multiplication/#comment-148</link>
		<dc:creator>Meta-Programming with Scala: Conditional Compilation and Loop Unrolling &#171; Michid&#8217;s Weblog</dc:creator>
		<pubDate>Wed, 29 Oct 2008 23:41:58 +0000</pubDate>
		<guid isPermaLink="false">http://michid.wordpress.com/?p=41#comment-148</guid>
		<description>[...] Compilation and Loop&#160;Unrolling  29 10 2008   The kind of comments I keep getting on my static meta-programming with Scala blogs are often along the lines of: &#8220;The ability to encode Church Numerals in [...]</description>
		<content:encoded><![CDATA[<p>[...] Compilation and Loop&nbsp;Unrolling  29 10 2008   The kind of comments I keep getting on my static meta-programming with Scala blogs are often along the lines of: &#8220;The ability to encode Church Numerals in [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Meta-Programming with Scala Part III: Partial function application &#171; Michid&#8217;s Weblog</title>
		<link>http://michid.wordpress.com/2008/07/30/meta-programming-with-scala-part-ii-multiplication/#comment-102</link>
		<dc:creator>Meta-Programming with Scala Part III: Partial function application &#171; Michid&#8217;s Weblog</dc:creator>
		<pubDate>Wed, 27 Aug 2008 22:35:16 +0000</pubDate>
		<guid isPermaLink="false">http://michid.wordpress.com/?p=41#comment-102</guid>
		<description>[...] with Scala Part III: Partial function&#160;application  27 08 2008    In my previous post about Meta-Programming with Scala I suspected that there was no way to express partial function [...]</description>
		<content:encoded><![CDATA[<p>[...] with Scala Part III: Partial function&nbsp;application  27 08 2008    In my previous post about Meta-Programming with Scala I suspected that there was no way to express partial function [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Landei</title>
		<link>http://michid.wordpress.com/2008/07/30/meta-programming-with-scala-part-ii-multiplication/#comment-70</link>
		<dc:creator>Landei</dc:creator>
		<pubDate>Fri, 01 Aug 2008 20:03:13 +0000</pubDate>
		<guid isPermaLink="false">http://michid.wordpress.com/?p=41#comment-70</guid>
		<description>This is a very simple but useful example for the use of recursive types, written in Java:

http://javatuple.com/

The used technique allows to define Tuples of arbitrary arity. It is probably not very efficient, and I doubt anyone needs more than Tuple22 in Scala, but it shows that this kind of stuff is not only &quot;academic&quot;.</description>
		<content:encoded><![CDATA[<p>This is a very simple but useful example for the use of recursive types, written in Java:</p>
<p><a href="http://javatuple.com/" rel="nofollow">http://javatuple.com/</a></p>
<p>The used technique allows to define Tuples of arbitrary arity. It is probably not very efficient, and I doubt anyone needs more than Tuple22 in Scala, but it shows that this kind of stuff is not only &#8220;academic&#8221;.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Matt Hellige</title>
		<link>http://michid.wordpress.com/2008/07/30/meta-programming-with-scala-part-ii-multiplication/#comment-69</link>
		<dc:creator>Matt Hellige</dc:creator>
		<pubDate>Fri, 01 Aug 2008 19:15:52 +0000</pubDate>
		<guid isPermaLink="false">http://michid.wordpress.com/?p=41#comment-69</guid>
		<description>Actually, you can sort of partially apply types, but you need to use a hack:
&lt;code&gt;
  trait apply1[t[_[_],_],u[_]] {
    type It[a] = t[u,a]
  }
&lt;/code&gt;
Notice that this needs to be defined for the specific kinds at which you intend to use it. (That is, if t and u had different kinds, one would need a different definition of apply1.) Then, we can write mul:
&lt;code&gt;
    type mul[m[s[_], z], n[s[_], z], s[_], z] = m[apply1[n,s]#It, z]
&lt;/code&gt;

This does work in at least some cases:
&lt;code&gt;
  type x[m[s[_], z], n[s[_], z]] = mul[m, n, Succ, Zero]
  println(depth(nullval[_3 x _2]))
&lt;/code&gt;
This takes ages to compile, but when it&#039;s done, it prints 6. Unfortunately, the same thing with &lt;code&gt;_2 x _2&lt;/code&gt; blows up badly (and breaks otherwise working code in the same file). I have no idea why... Probably I&#039;ll post to the list about it.

(I can&#039;t preview this comment, I guess. I hope the code comes out ok.)</description>
		<content:encoded><![CDATA[<p>Actually, you can sort of partially apply types, but you need to use a hack:<br />
<code><br />
  trait apply1[t[_[_],_],u[_]] {<br />
    type It[a] = t[u,a]<br />
  }<br />
</code><br />
Notice that this needs to be defined for the specific kinds at which you intend to use it. (That is, if t and u had different kinds, one would need a different definition of apply1.) Then, we can write mul:<br />
<code><br />
    type mul[m[s[_], z], n[s[_], z], s[_], z] = m[apply1[n,s]#It, z]<br />
</code></p>
<p>This does work in at least some cases:<br />
<code><br />
  type x[m[s[_], z], n[s[_], z]] = mul[m, n, Succ, Zero]<br />
  println(depth(nullval[_3 x _2]))<br />
</code><br />
This takes ages to compile, but when it&#8217;s done, it prints 6. Unfortunately, the same thing with <code>_2 x _2</code> blows up badly (and breaks otherwise working code in the same file). I have no idea why&#8230; Probably I&#8217;ll post to the list about it.</p>
<p>(I can&#8217;t preview this comment, I guess. I hope the code comes out ok.)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: michid</title>
		<link>http://michid.wordpress.com/2008/07/30/meta-programming-with-scala-part-ii-multiplication/#comment-68</link>
		<dc:creator>michid</dc:creator>
		<pubDate>Thu, 31 Jul 2008 08:07:06 +0000</pubDate>
		<guid isPermaLink="false">http://michid.wordpress.com/?p=41#comment-68</guid>
		<description>@Daniel: Encoding Church Numerals in Scala&#039;s type system is by itself pure academic. However, my intention was to use it as a starting point to go further from there: if it had worked out, one might have come up with an general encoding of some class of functions (most probably the primitive recursive functions). While this again is academic, it would give a clear picture of what the type system is capable of. It might have ultimately lead to constructs similar in power to those used in C++ template meta programming (which to me seems rather esoteric than academic ;-) ).</description>
		<content:encoded><![CDATA[<p>@Daniel: Encoding Church Numerals in Scala&#8217;s type system is by itself pure academic. However, my intention was to use it as a starting point to go further from there: if it had worked out, one might have come up with an general encoding of some class of functions (most probably the primitive recursive functions). While this again is academic, it would give a clear picture of what the type system is capable of. It might have ultimately lead to constructs similar in power to those used in C++ template meta programming (which to me seems rather esoteric than academic <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' />  ).</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Daniel Spiewak</title>
		<link>http://michid.wordpress.com/2008/07/30/meta-programming-with-scala-part-ii-multiplication/#comment-67</link>
		<dc:creator>Daniel Spiewak</dc:creator>
		<pubDate>Thu, 31 Jul 2008 04:46:28 +0000</pubDate>
		<guid isPermaLink="false">http://michid.wordpress.com/?p=41#comment-67</guid>
		<description>The ability to encode Church Numerals in Scala still seems uselessly academic to me, but cool none-the-less.  :-)  Scala&#039;s type system is impressively powerful, but as this post shows, it does have its limits.  For me, the fact that it is not possible to define recursive types is rather annoying.  Granted, it&#039;s not a requirement which comes up very often, but it is certainly bothersome when it does.</description>
		<content:encoded><![CDATA[<p>The ability to encode Church Numerals in Scala still seems uselessly academic to me, but cool none-the-less.  <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' />   Scala&#8217;s type system is impressively powerful, but as this post shows, it does have its limits.  For me, the fact that it is not possible to define recursive types is rather annoying.  Granted, it&#8217;s not a requirement which comes up very often, but it is certainly bothersome when it does.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
