[Haskell-cafe] How to fulfill the "code-reuse" destiny of OOP?
ganesh.sittampalam at credit-suisse.com
Wed Jan 13 05:00:32 EST 2010
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).
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.
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
From: haskell-cafe-bounces at haskell.org
[mailto:haskell-cafe-bounces at haskell.org] On Behalf Of Peter Verswyvelen
Sent: 13 January 2010 09:52
To: Gregory Collins
Cc: haskell-cafe at haskell.org
Subject: Re: [Haskell-cafe] How to fulfill the "code-reuse" destiny of
On Sun, Nov 1, 2009 at 2:57 AM, Gregory Collins
<greg at gregorycollins.net> wrote:
Doing OO-style programming in Haskell is difficult and
true (although technically speaking it is possible). That said,
yet to present a convincing argument to me why Java gets a free
lacking closures and typeclasses.
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?
An inner class allows you to implicitly capture the parent object
("environment"), just like a closure does in a sense.
Interfaces group together methods, like type classes do.
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
Please access the attached hyperlink for an important electronic communications disclaimer:
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Haskell-Cafe