<?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"
	>
<channel>
	<title>Comments on: Funky Scala Bifunctor</title>
	<atom:link href="http://blog.tmorris.net/funky-scala-bifunctor/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.tmorris.net/funky-scala-bifunctor/</link>
	<description>The weblog of Tony Morris</description>
	<pubDate>Sat, 19 May 2012 02:42:05 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.6</generator>
		<item>
		<title>By: Tony Morris</title>
		<link>http://blog.tmorris.net/funky-scala-bifunctor/#comment-32083</link>
		<dc:creator>Tony Morris</dc:creator>
		<pubDate>Mon, 16 Feb 2009 20:50:01 +0000</pubDate>
		<guid isPermaLink="false">http://blog.tmorris.net/?p=542#comment-32083</guid>
		<description>A kind declaration simply declares the kind of type constructor. F[_, _] clearly declares the kind. Contrast this to Haskell where the kind is inferred. This is because Haskell infers kinds, while Scala cannot.

As for using partially-applied type constructor arguments, I do it several times a day on a commercial project without blinking an eye.</description>
		<content:encoded><![CDATA[<p>A kind declaration simply declares the kind of type constructor. F[_, _] clearly declares the kind. Contrast this to Haskell where the kind is inferred. This is because Haskell infers kinds, while Scala cannot.</p>
<p>As for using partially-applied type constructor arguments, I do it several times a day on a commercial project without blinking an eye.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Daniel Spiewak</title>
		<link>http://blog.tmorris.net/funky-scala-bifunctor/#comment-32077</link>
		<dc:creator>Daniel Spiewak</dc:creator>
		<pubDate>Mon, 16 Feb 2009 18:31:46 +0000</pubDate>
		<guid isPermaLink="false">http://blog.tmorris.net/?p=542#comment-32077</guid>
		<description>&#62; this contains a kind declaration

I guess it depends on what you see as a kind declaration.  To me, a kind declaration has to be something of the following form:

&lt;pre&gt;Bifunctor :: * =&#62; * =&#62; *&lt;/pre&gt;

(shamelessly borrowing from Haskell and formal kind notation)

I would see this as an *explicit* kind annotation, where as &lt;code&gt;Bifunctor[F[_, _]]&lt;/code&gt; is perhaps more of an *implicit* notational form.  I suppose that technically, they're both a way of declaring kind, at some level.  The difference would be that the explicit notation is actually defining the kind, whereas Scala's implicit notation is implying a kind by being extremely explicit about the type.

I was aware of the partially-applied type constructors idea -- I read Mitch's blog whenever I need convincing that I know a lot less than I think I do.  :-)  It is definitely a neat trick, though I can't see myself ever using it for any real-world application.  One possible exception would be a DSL which type-checks some advanced concept.  Thus, a DSL which is correct (or rather, *runnable*) by construction.  However, given how horribly explicit Scala's type system can be, I doubt the syntax would ever be accepted.</description>
		<content:encoded><![CDATA[<p>&gt; this contains a kind declaration</p>
<p>I guess it depends on what you see as a kind declaration.  To me, a kind declaration has to be something of the following form:</p>
<pre>Bifunctor :: * =&gt; * =&gt; *</pre>
<p>(shamelessly borrowing from Haskell and formal kind notation)</p>
<p>I would see this as an *explicit* kind annotation, where as <code>Bifunctor[F[_, _]]</code> is perhaps more of an *implicit* notational form.  I suppose that technically, they&#8217;re both a way of declaring kind, at some level.  The difference would be that the explicit notation is actually defining the kind, whereas Scala&#8217;s implicit notation is implying a kind by being extremely explicit about the type.</p>
<p>I was aware of the partially-applied type constructors idea &#8212; I read Mitch&#8217;s blog whenever I need convincing that I know a lot less than I think I do.  <img src='http://blog.tmorris.net/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' />  It is definitely a neat trick, though I can&#8217;t see myself ever using it for any real-world application.  One possible exception would be a DSL which type-checks some advanced concept.  Thus, a DSL which is correct (or rather, *runnable*) by construction.  However, given how horribly explicit Scala&#8217;s type system can be, I doubt the syntax would ever be accepted.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Tony Morris</title>
		<link>http://blog.tmorris.net/funky-scala-bifunctor/#comment-31904</link>
		<dc:creator>Tony Morris</dc:creator>
		<pubDate>Sat, 14 Feb 2009 20:15:35 +0000</pubDate>
		<guid isPermaLink="false">http://blog.tmorris.net/?p=542#comment-31904</guid>
		<description>"I don’t see any kind declaration here."

There is one ;)

&lt;pre lang="Scala"&gt;
// this contains a kind declaration
Bifunctor[F[_, _]]
&lt;/pre&gt;

Consider Haskell:

&lt;pre lang="Haskell"&gt;
-- no kind declaration though with GHC extensions it is possible
class Bifunctor f
&lt;/pre&gt;

Nevertheless, this is not what I meant. Rather, type constructors of a higher-kind are never inferred.

While Scala's type constructors are uncurried, this is not too bothersome in this example, however, it certainly can be. There is a neat trick that allows you to partially apply type variables.

For example
&lt;pre lang="Scala"&gt;
trait PartialType[T[_, _], A] {
  type Apply[B] = T[A, B]

  type Flip[B] = T[B, A]
}
&lt;/pre&gt;

This allows you to declared type constructors such as:
&lt;pre lang="Scala"&gt;
Bifunctor#Apply[Int]
// or
Bifunctor#Flip[String]
&lt;/pre&gt;</description>
		<content:encoded><![CDATA[<p>&#8220;I don’t see any kind declaration here.&#8221;</p>
<p>There is one <img src='http://blog.tmorris.net/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>

<div class="wp_syntax"><div class="code"><pre class="scala"><span style="color: #008000; font-style: italic;">// this contains a kind declaration</span>
Bifunctor<span style="color: #F78811;">&#91;</span>F<span style="color: #F78811;">&#91;</span><span style="color: #000080;">_</span>, <span style="color: #000080;">_</span><span style="color: #F78811;">&#93;</span><span style="color: #F78811;">&#93;</span></pre></div></div>

<p>Consider Haskell:</p>

<div class="wp_syntax"><div class="code"><pre class="haskell"><span style="color: #5d478b; font-style: italic;">-- no kind declaration though with GHC extensions it is possible</span>
<span style="color: #06c; font-weight: bold;">class</span> Bifunctor f</pre></div></div>

<p>Nevertheless, this is not what I meant. Rather, type constructors of a higher-kind are never inferred.</p>
<p>While Scala&#8217;s type constructors are uncurried, this is not too bothersome in this example, however, it certainly can be. There is a neat trick that allows you to partially apply type variables.</p>
<p>For example</p>

<div class="wp_syntax"><div class="code"><pre class="scala"><span style="color: #0000ff; font-weight: bold;">trait</span> PartialType<span style="color: #F78811;">&#91;</span>T<span style="color: #F78811;">&#91;</span><span style="color: #000080;">_</span>, <span style="color: #000080;">_</span><span style="color: #F78811;">&#93;</span>, A<span style="color: #F78811;">&#93;</span> <span style="color: #F78811;">&#123;</span>
  <span style="color: #0000ff; font-weight: bold;">type</span> Apply<span style="color: #F78811;">&#91;</span>B<span style="color: #F78811;">&#93;</span> <span style="color: #000080;">=</span> T<span style="color: #F78811;">&#91;</span>A, B<span style="color: #F78811;">&#93;</span>
&nbsp;
  <span style="color: #0000ff; font-weight: bold;">type</span> Flip<span style="color: #F78811;">&#91;</span>B<span style="color: #F78811;">&#93;</span> <span style="color: #000080;">=</span> T<span style="color: #F78811;">&#91;</span>B, A<span style="color: #F78811;">&#93;</span>
<span style="color: #F78811;">&#125;</span></pre></div></div>

<p>This allows you to declared type constructors such as:</p>

<div class="wp_syntax"><div class="code"><pre class="scala">Bifunctor<span style="color: #000080;">#</span>Apply<span style="color: #F78811;">&#91;</span><span style="color: #9999cc; font-weight: bold;">Int</span><span style="color: #F78811;">&#93;</span>
<span style="color: #008000; font-style: italic;">// or</span>
Bifunctor<span style="color: #000080;">#</span>Flip<span style="color: #F78811;">&#91;</span>String<span style="color: #F78811;">&#93;</span></pre></div></div>

]]></content:encoded>
	</item>
	<item>
		<title>By: Daniel Spiewak</title>
		<link>http://blog.tmorris.net/funky-scala-bifunctor/#comment-31886</link>
		<dc:creator>Daniel Spiewak</dc:creator>
		<pubDate>Sat, 14 Feb 2009 17:11:51 +0000</pubDate>
		<guid isPermaLink="false">http://blog.tmorris.net/?p=542#comment-31886</guid>
		<description>Actually, higher-kinds in Scala are *always* inferred (see the "Toward Higher Kinds..." paper, Odersky et al).  It is merely the types themselves which are not reconstructed.  Your own source code shows this:

&lt;pre&gt;trait Bifunctor[F[+_, +_]] {&lt;/pre&gt;

I don't see any kind declaration here.  Scala *infers* that F is of kind * =&#62; * =&#62; * (or perhaps more correctly, (*, *) =&#62; *).  In fact, there is no way (in Scala) to ever declare that a type is of one kind or another, you have to trust the compiler to figure it out every time.

Therein lies the problem, as it means that you have to be painfully explicit about some declarations (such as Bifunctor).  A language with a more universal type inference/reconstruction would be able to see that we're instantiating the F type constructor within the declaration for the bimap method, thus it must be of a certain kind.</description>
		<content:encoded><![CDATA[<p>Actually, higher-kinds in Scala are *always* inferred (see the &#8220;Toward Higher Kinds&#8230;&#8221; paper, Odersky et al).  It is merely the types themselves which are not reconstructed.  Your own source code shows this:</p>
<pre>trait Bifunctor[F[+_, +_]] {</pre>
<p>I don&#8217;t see any kind declaration here.  Scala *infers* that F is of kind * =&gt; * =&gt; * (or perhaps more correctly, (*, *) =&gt; *).  In fact, there is no way (in Scala) to ever declare that a type is of one kind or another, you have to trust the compiler to figure it out every time.</p>
<p>Therein lies the problem, as it means that you have to be painfully explicit about some declarations (such as Bifunctor).  A language with a more universal type inference/reconstruction would be able to see that we&#8217;re instantiating the F type constructor within the declaration for the bimap method, thus it must be of a certain kind.</p>
]]></content:encoded>
	</item>
</channel>
</rss>

