<?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: Type-classes are nothing like interfaces</title>
	<atom:link href="http://blog.tmorris.net/type-classes-are-nothing-like-interfaces/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.tmorris.net/type-classes-are-nothing-like-interfaces/</link>
	<description>The weblog of Tony Morris</description>
	<pubDate>Sat, 19 May 2012 03:14:05 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.6</generator>
		<item>
		<title>By: Raven</title>
		<link>http://blog.tmorris.net/type-classes-are-nothing-like-interfaces/#comment-40145</link>
		<dc:creator>Raven</dc:creator>
		<pubDate>Fri, 30 Apr 2010 08:07:30 +0000</pubDate>
		<guid isPermaLink="false">http://blog.tmorris.net/?p=736#comment-40145</guid>
		<description>How about C#'s generic type constraints? Something like:
public static Sort&#60;T&#62;(this IEnumerable&#60;T&#62; xs) where T : IComparable&#60;T&#62; { ... }
notice the "IComparable&#60;T&#62;" as opposed to "IComparator&#60;T&#62;", where the objects being sorted know how to sort themselves, thus "implicit"</description>
		<content:encoded><![CDATA[<p>How about C#&#8217;s generic type constraints? Something like:<br />
public static Sort&lt;T&gt;(this IEnumerable&lt;T&gt; xs) where T : IComparable&lt;T&gt; { &#8230; }<br />
notice the &#8220;IComparable&lt;T&gt;&#8221; as opposed to &#8220;IComparator&lt;T&gt;&#8221;, where the objects being sorted know how to sort themselves, thus &#8220;implicit&#8221;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Tony Morris</title>
		<link>http://blog.tmorris.net/type-classes-are-nothing-like-interfaces/#comment-39696</link>
		<dc:creator>Tony Morris</dc:creator>
		<pubDate>Fri, 16 Apr 2010 00:41:04 +0000</pubDate>
		<guid isPermaLink="false">http://blog.tmorris.net/?p=736#comment-39696</guid>
		<description>Yes Dan, this is exactly correct.

&lt;pre lang="Haskell"&gt;
newtype Product = Product Int
newtype Sum = Sum Int

instance Monoid Product where
  ...

instance Monoid Sum where
  ...
&lt;/pre&gt;</description>
		<content:encoded><![CDATA[<p>Yes Dan, this is exactly correct.</p>

<div class="wp_syntax"><div class="code"><pre class="haskell"><span style="color: #06c; font-weight: bold;">newtype</span> Product <span style="color: #339933; font-weight: bold;">=</span> Product <span style="color: #cccc00; font-weight: bold;">Int</span>
<span style="color: #06c; font-weight: bold;">newtype</span> Sum <span style="color: #339933; font-weight: bold;">=</span> Sum <span style="color: #cccc00; font-weight: bold;">Int</span>
&nbsp;
<span style="color: #06c; font-weight: bold;">instance</span> Monoid Product <span style="color: #06c; font-weight: bold;">where</span>
  <span style="color: #339933; font-weight: bold;">...</span>
&nbsp;
<span style="color: #06c; font-weight: bold;">instance</span> Monoid Sum <span style="color: #06c; font-weight: bold;">where</span>
  <span style="color: #339933; font-weight: bold;">...</span></pre></div></div>

]]></content:encoded>
	</item>
	<item>
		<title>By: Dan</title>
		<link>http://blog.tmorris.net/type-classes-are-nothing-like-interfaces/#comment-39681</link>
		<dc:creator>Dan</dc:creator>
		<pubDate>Thu, 15 Apr 2010 16:35:41 +0000</pubDate>
		<guid isPermaLink="false">http://blog.tmorris.net/?p=736#comment-39681</guid>
		<description>Also, for example, the Product and Sum monoids on integers? There was a good example of differentiating between the two on sigfpe a while back: [http://blog.sigfpe.com/2009/01/haskell-monoids-and-their-uses.html].

In that example, one assigns an existing class to a type class using the instance keyword. You're suggesting that one first duplicate an existing class (eg, newtype another_name_for_type = original_type) then use instance on another_name_for_type?

That makes sense; it solves the explicit-implicit problem just as well.

Thanks!</description>
		<content:encoded><![CDATA[<p>Also, for example, the Product and Sum monoids on integers? There was a good example of differentiating between the two on sigfpe a while back: [http://blog.sigfpe.com/2009/01/haskell-monoids-and-their-uses.html].</p>
<p>In that example, one assigns an existing class to a type class using the instance keyword. You&#8217;re suggesting that one first duplicate an existing class (eg, newtype another_name_for_type = original_type) then use instance on another_name_for_type?</p>
<p>That makes sense; it solves the explicit-implicit problem just as well.</p>
<p>Thanks!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Tony Morris</title>
		<link>http://blog.tmorris.net/type-classes-are-nothing-like-interfaces/#comment-39639</link>
		<dc:creator>Tony Morris</dc:creator>
		<pubDate>Wed, 14 Apr 2010 21:43:33 +0000</pubDate>
		<guid isPermaLink="false">http://blog.tmorris.net/?p=736#comment-39639</guid>
		<description>Hi Dan,
In Haskell it is generally considered poor form to instance a type-class more than once for a type. For example, the boolean &#124;&#124;/True and the &#038;&#038;/False monoid.

It is recommended instead to "newtype" the type then instance that, requiring the user to wrap/unwrap depending which instance they'd like to use. This is quite clumsy, but I've not seen a better solution to this problem.</description>
		<content:encoded><![CDATA[<p>Hi Dan,<br />
In Haskell it is generally considered poor form to instance a type-class more than once for a type. For example, the boolean ||/True and the &#038;&#038;/False monoid.</p>
<p>It is recommended instead to &#8220;newtype&#8221; the type then instance that, requiring the user to wrap/unwrap depending which instance they&#8217;d like to use. This is quite clumsy, but I&#8217;ve not seen a better solution to this problem.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Dan</title>
		<link>http://blog.tmorris.net/type-classes-are-nothing-like-interfaces/#comment-39636</link>
		<dc:creator>Dan</dc:creator>
		<pubDate>Wed, 14 Apr 2010 18:46:45 +0000</pubDate>
		<guid isPermaLink="false">http://blog.tmorris.net/?p=736#comment-39636</guid>
		<description>Presumably, a type 'a can have more than one comparator. What is the mechanism for choosing between them?

In Scala, only one implicit can be in scope else the implicit must be passed, well, explicitly. Is there something similar in Haskell?</description>
		<content:encoded><![CDATA[<p>Presumably, a type &#8216;a can have more than one comparator. What is the mechanism for choosing between them?</p>
<p>In Scala, only one implicit can be in scope else the implicit must be passed, well, explicitly. Is there something similar in Haskell?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Tony Morris</title>
		<link>http://blog.tmorris.net/type-classes-are-nothing-like-interfaces/#comment-39585</link>
		<dc:creator>Tony Morris</dc:creator>
		<pubDate>Tue, 13 Apr 2010 10:14:07 +0000</pubDate>
		<guid isPermaLink="false">http://blog.tmorris.net/?p=736#comment-39585</guid>
		<description>Indeed. I have been meaning to write a post about the relationship between implicit conversion (ala Scala) and inheritance. There are some key differences between the two and especially, differences with practical implications, but there are also many insightful similarities that can be used in such a way as to say "implicit conversion is not as foreign as may seem, if you are perfectly comfortable with the idea of inheritance".

I also think this is beneficial in terms of the strong aversion to syntax such as &lt;code&gt;A =&gt; B&lt;/code&gt; yet there is no such aversion when the arrow is pointing upward as in inheritance (i.e. as a hint: they are the same arrow! just tilt your head 90 degrees if it helps!). This also draws on the concept of logical implication and the relationship to programming (Curry-Howard Correspondence).

So many things to say :)</description>
		<content:encoded><![CDATA[<p>Indeed. I have been meaning to write a post about the relationship between implicit conversion (ala Scala) and inheritance. There are some key differences between the two and especially, differences with practical implications, but there are also many insightful similarities that can be used in such a way as to say &#8220;implicit conversion is not as foreign as may seem, if you are perfectly comfortable with the idea of inheritance&#8221;.</p>
<p>I also think this is beneficial in terms of the strong aversion to syntax such as <code>A => B</code> yet there is no such aversion when the arrow is pointing upward as in inheritance (i.e. as a hint: they are the same arrow! just tilt your head 90 degrees if it helps!). This also draws on the concept of logical implication and the relationship to programming (Curry-Howard Correspondence).</p>
<p>So many things to say <img src='http://blog.tmorris.net/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Christian Szegedy</title>
		<link>http://blog.tmorris.net/type-classes-are-nothing-like-interfaces/#comment-39565</link>
		<dc:creator>Christian Szegedy</dc:creator>
		<pubDate>Tue, 13 Apr 2010 00:50:26 +0000</pubDate>
		<guid isPermaLink="false">http://blog.tmorris.net/?p=736#comment-39565</guid>
		<description>Thanks :)

You also note in the last section of your post dictionary passing and implicit type conversion happens in java (to some extent) for interfaces via the inheritance mechanism.

So the difference is rather that in the case of type classes you have to define the adherence to the interface at the place of the declaration of the data type, whereas in the the case of type classes it can happen more flexibly in a decoupled way (as you note it in the same section).

I definitely agree with you that equating type classes to interfaces is a very bad idea from an educational point of view, since it would mainly focus on the commonalities rather than the important differences.

BTW, in my view implicit conversion is really not so different from inheritance either. the main difference being the decoupled nature of declaration: if there would be a fully transitive system of implicit conversions, you could easily emulate inheritance, but not vica versa.

OTOH, type classes are more restrictive than arbitrary type conversions (which is a great thing IMO), so with the same logic as this post, you could also blog "Type conversions are nothing like type classes". Whereas in my view, there is a continuum:

interfaces &#60; type classes &#60; type conversions

of increasingly flexible solutions.</description>
		<content:encoded><![CDATA[<p>Thanks <img src='http://blog.tmorris.net/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>You also note in the last section of your post dictionary passing and implicit type conversion happens in java (to some extent) for interfaces via the inheritance mechanism.</p>
<p>So the difference is rather that in the case of type classes you have to define the adherence to the interface at the place of the declaration of the data type, whereas in the the case of type classes it can happen more flexibly in a decoupled way (as you note it in the same section).</p>
<p>I definitely agree with you that equating type classes to interfaces is a very bad idea from an educational point of view, since it would mainly focus on the commonalities rather than the important differences.</p>
<p>BTW, in my view implicit conversion is really not so different from inheritance either. the main difference being the decoupled nature of declaration: if there would be a fully transitive system of implicit conversions, you could easily emulate inheritance, but not vica versa.</p>
<p>OTOH, type classes are more restrictive than arbitrary type conversions (which is a great thing IMO), so with the same logic as this post, you could also blog &#8220;Type conversions are nothing like type classes&#8221;. Whereas in my view, there is a continuum:</p>
<p>interfaces &lt; type classes &lt; type conversions</p>
<p>of increasingly flexible solutions.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Tony Morris</title>
		<link>http://blog.tmorris.net/type-classes-are-nothing-like-interfaces/#comment-39461</link>
		<dc:creator>Tony Morris</dc:creator>
		<pubDate>Sat, 10 Apr 2010 02:10:34 +0000</pubDate>
		<guid isPermaLink="false">http://blog.tmorris.net/?p=736#comment-39461</guid>
		<description>Christian,
An essential property of type-classes is the implicit dictionary passing. In the absence of this, you have a regular data type. Interfaces do not have implicit dictionary passing and are precisely equivalent to a regular data type. Interfaces do not have the key essential property that makes type-classes distinct: implicit dictionary passing. Without implicit dictionary you have regular data types, which are exactly equivalent to interfaces. Interfaces are exactly like data types. Data types are distinguished from type-classes by virtue of the requirement for explicit passing. Type-classes have implicit dictionary passing. Without implicit dictionary passing, type-classes would be something else, such as data types.

Hope that helps.</description>
		<content:encoded><![CDATA[<p>Christian,<br />
An essential property of type-classes is the implicit dictionary passing. In the absence of this, you have a regular data type. Interfaces do not have implicit dictionary passing and are precisely equivalent to a regular data type. Interfaces do not have the key essential property that makes type-classes distinct: implicit dictionary passing. Without implicit dictionary you have regular data types, which are exactly equivalent to interfaces. Interfaces are exactly like data types. Data types are distinguished from type-classes by virtue of the requirement for explicit passing. Type-classes have implicit dictionary passing. Without implicit dictionary passing, type-classes would be something else, such as data types.</p>
<p>Hope that helps.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Christian Szegedy</title>
		<link>http://blog.tmorris.net/type-classes-are-nothing-like-interfaces/#comment-39449</link>
		<dc:creator>Christian Szegedy</dc:creator>
		<pubDate>Fri, 09 Apr 2010 17:40:56 +0000</pubDate>
		<guid isPermaLink="false">http://blog.tmorris.net/?p=736#comment-39449</guid>
		<description>Great factual answer. Finally, you convinced me.</description>
		<content:encoded><![CDATA[<p>Great factual answer. Finally, you convinced me.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Tony Morris</title>
		<link>http://blog.tmorris.net/type-classes-are-nothing-like-interfaces/#comment-39422</link>
		<dc:creator>Tony Morris</dc:creator>
		<pubDate>Fri, 09 Apr 2010 02:54:40 +0000</pubDate>
		<guid isPermaLink="false">http://blog.tmorris.net/?p=736#comment-39422</guid>
		<description>Christian, I explained exactly why type-classes are nothing like interfaces. It seems you missed it. There is no parallel to "worth noting."</description>
		<content:encoded><![CDATA[<p>Christian, I explained exactly why type-classes are nothing like interfaces. It seems you missed it. There is no parallel to &#8220;worth noting.&#8221;</p>
]]></content:encoded>
	</item>
</channel>
</rss>

