<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">
  <channel>
    <title>
      Marakana
      -
      Scala - Examples Forum</title>
    <link>
      http://marakana.com/forums/scala/examples/</link>
    <description>Scala examples is the place to learn about Scala language through short to-the-point code examples. Enjoy!</description>
    <copyright>2012 Marakana Inc, purveyors of fine training since 2005.</copyright><generator>Marakana Spark</generator>
    <item>
        <title>a more readable type lambda trick</title>
        <link>http://marakana.com/forums/scala/examples/665.html</link>
        <author>Dan Rosen</author>
        <guid isPermaLink="true">http://marakana.com/forums/scala/examples/665.html</guid>
        <pubDate>Sat, 31 Mar 2012 09:43:58 -0700</pubDate>
        <category>Scala - Examples</category>
        <content:encoded><![CDATA[So you've got some type that takes multiple type parameters, like:<br/><br/><div class="code">
		    <span>Code:</span><br/>
		    <pre style="height:expression(this.scrollHeight > 350 ? '350px' : 'auto');">trait State[S, A]<br/></pre>
		  </div><br/><br/>... and you've got some code that needs to fix one of the type parameters while letting the other(s) vary.  We usually use the "type lambda trick" to partially apply type arguments, like this:<br/><br/><div class="code">
		    <span>Code:</span><br/>
		    <pre style="height:expression(this.scrollHeight > 350 ? '350px' : 'auto');">def stateMonad[S] = new Monad[({type L[A] = State[S, A]})#L] { ... }<br/></pre>
		  </div><br/><br/>Sometimes you see this written with actual Greek characters using Unicode, where "L" is written as a lower case lambda, hence the name.  Using Greek letters in source code is for jerks, unless you happen to actually be Greek, in which case go for it.  However, even with the Latin "L" I don't find this style of code particularly readable, when some type lambda needs to be given a name and referenced more than once.  <strong>So I propose the following new convention:</strong><br/><br/><div class="code">
		    <span>Code:</span><br/>
		    <pre style="height:expression(this.scrollHeight > 350 ? '350px' : 'auto');">def stateMonad[S] = {<br/>  type `State[S]`[A] = State[S, A]<br/>  new Monad[`State[S]`] { ... }<br/>}<br/></pre>
		  </div><br/><br/>The backticks permit use of the special <code class="inline">[]</code> characters which wouldn't otherwise be allowed in an identifier.  At any rate, the idea is to mimic the appearance of <a href="https://issues.scala-lang.org/browse/SI-4719" rel="nofollow">multiple type parameter lists</a> without yet having them in the Scala language.]]></content:encoded>
      </item>
    </channel>
</rss>