[Haskell-cafe] How to fulfill the "code-reuse" destiny of OOP?

Robert Greayer robgreayer at gmail.com
Wed Jan 13 12:05:33 EST 2010

On Wed, Jan 13, 2010 at 4:56 AM, Martin Coxall <pseudo.meta at me.com> wrote:
> On 13 Jan 2010, at 09:51, Peter Verswyvelen wrote:
> 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 unnatural, it's
>> true (although technically speaking it is possible). That said, nobody's
>> yet to present a convincing argument to me why Java gets a free pass for
>> 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?
> Inner classes are not a semantic replacement for closures, even if you
> discount horrific syntax. Inner classes do not close over their lexical
> environment.
> Martin

Anonymous classes in Java close over their lexical environment (can
refer to variables in that lexical environment, with values bound at
the time of instance construction) with the caveat that only local
variables/parameters marked as 'final' may be referred to.  Aside from
the horrible syntax, this is the key distinction between them, and,
say, Ruby closures.  Referring to mutable variables from inside a
closure has its drawbacks, making the horrible syntax the biggest
stumbling block to using them IMHO (other than runtime overhead, which
I believe is also an issue).

More information about the Haskell-Cafe mailing list