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

Sebastian Sylvan sebastian.sylvan at gmail.com
Sat Oct 31 22:39:52 EDT 2009


On Sun, Nov 1, 2009 at 2:00 AM, Michael Vanier <mvanier42 at gmail.com> wrote:

> Gregory Collins wrote:
>
>> Tom Davie <tom.davie at gmail.com> writes:
>>
>>
>>
>>> On 10/31/09, Magicloud Magiclouds <magicloud.magiclouds at gmail.com>
>>> wrote:
>>>
>>>
>>>> After all, I never think OO as an oppsite way to all other things. The
>>>> idea is so general that if you say I cannot use it in Haskell at all,
>>>> that would make me feel weird. The only difference between languages
>>>> is, some are easy to be in OO style, some are not.
>>>>
>>>>
>>> Wow, someone drank the cool aid!
>>>
>>>
>>
>> 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.
>>
>> G.
>>
>>
> Because most programmers have never heard of closures and typeclasses, and
> thus have no idea how useful they are? :-(
>
> BTW using existential types in Haskell you can mimic OO to a pretty decent
> degree, at least as far as interfaces are concerned.
>

I kind of wish we had some convenience notation for doing value-based
dispatch like that.... Something like

foo :: [ <Show> ] -> String
foo xs = concatMap show xs

> foo [ 5, True, 1.3 ]
"5True1.3"


(where wrapping a class up in angle brackets makes it into an existentially
qualified wrapper, which is instantiated in the class itself -- maybe we
need explicit conversion from e.g. Int to <Show> though...)

You don't need it very often, but I wonder if that's because there genuinely
isn't a need, or if you tend to avoid writing code in ways which would need
it (ask a Java programmer, and they'll probably tell you that the need for
type classes and closures don't come up very often - which is clearly untrue
for a Haskell programmer).

-- 
Sebastian Sylvan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20091031/d83b8105/attachment.html


More information about the Haskell-Cafe mailing list