<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=us-ascii">
<META content="MSHTML 6.00.2900.3603" name=GENERATOR></HEAD>
<BODY>
<DIV dir=ltr align=left><SPAN class=884255309-13012010><FONT face=Arial
color=#008000 size=2>The problem with interfaces as a replacement for type
classes is that they only provide dispatch based on the specific type of the
first argument (i.e. the receiver).</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=884255309-13012010><FONT face=Arial
color=#008000 size=2></FONT></SPAN> </DIV>
<DIV dir=ltr align=left><SPAN class=884255309-13012010><FONT face=Arial
color=#008000 size=2>Type classes allow you to dispatch based on return
type, and on the instantiations of generic parameters. Neither of these things
is reasonably possible with interfaces.</FONT></SPAN></DIV>
<DIV> </DIV>
<DIV><FONT face=Arial color=#008000 size=2><SPAN class=884255309-13012010>For
example you can't directly implement the Read type class with interfaces.
Neither can you implement a function of type [a] -> ... where the
dispatch is based on the instantiation of a - even if you can add an interface
to the [] generic type, you might not have a concrete object of type a to
dispatch from if the empty list is passed as an argument.</SPAN></FONT></DIV>
<DIV><FONT face=Arial color=#008000 size=2></FONT> </DIV>
<DIV><BR></DIV>
<DIV class=OutlookMessageHeader lang=en-us dir=ltr align=left>
<HR tabIndex=-1>
<FONT face=Tahoma size=2><B>From:</B> haskell-cafe-bounces@haskell.org
[mailto:haskell-cafe-bounces@haskell.org] <B>On Behalf Of </B>Peter
Verswyvelen<BR><B>Sent:</B> 13 January 2010 09:52<BR><B>To:</B> Gregory
Collins<BR><B>Cc:</B> haskell-cafe@haskell.org<BR><B>Subject:</B> Re:
[Haskell-cafe] How to fulfill the "code-reuse" destiny of
OOP?<BR></FONT><BR></DIV>
<DIV></DIV>
<DIV class=gmail_quote>On Sun, Nov 1, 2009 at 2:57 AM, Gregory Collins <SPAN
dir=ltr><<A
href="mailto:greg@gregorycollins.net">greg@gregorycollins.net</A>></SPAN>
wrote:<BR>
<BLOCKQUOTE class=gmail_quote
style="PADDING-LEFT: 1ex; MARGIN: 0px 0px 0px 0.8ex; BORDER-LEFT: #ccc 1px solid">
<DIV class=im>Doing OO-style programming in Haskell is difficult and
unnatural, it's</DIV>true (although technically speaking it is possible). That
said, nobody's<BR>yet to present a convincing argument to me why Java gets a
free pass for<BR>lacking closures and typeclasses.<BR></BLOCKQUOTE>
<DIV><BR></DIV>
<DIV>I might be wrong, but doesn't Java's concepts of inner classes and
interfaces together with adapter classes can be used to replace closures and
typeclasses in a way?</DIV>
<DIV><BR></DIV>
<DIV>An inner class allows you to implicitly capture the parent object
("environment"), just like a closure does in a sense.</DIV>
<DIV><BR></DIV>
<DIV>Interfaces group together methods, like type classes do. </DIV>
<DIV><BR></DIV>
<DIV>Although I'm actually a C# fanboy for doing "industrial" programming, I
think the Java designers did an excellent job, finding a good balance in
language features, ease of use and readability, and although C# does offer
closures and many more FP constructs, I really miss the above Java
constructs.</DIV>
<DIV><BR></DIV></DIV><BR></BODY></HTML>
<BR/><!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><p class=MsoNormal><span lang=EN-US style='font-size:8.0pt;font-family:Courier'>==============================================================================<br>Please access the attached hyperlink for an important electronic communications disclaimer:<br><a href="http://www.credit-suisse.com/legal/en/disclaimer_email_ib.html">http://www.credit-suisse.com/legal/en/disclaimer_email_ib.html</a><br>==============================================================================<o:p></o:p></span></p></html><br>