by pjmlp · 6y ago · 0 comments
They surely do, OOP like FP, is very fuzzy and since the Simula/Smalltalk days there have been multiple ways to try to represent OOP concepts.
There isn't any OOP language that implements every OOP idea, just like there isn't any FP language that implements every FP idea.
Type classes allow for polymorphism, and combined with modules one can make use of module private implementations for the encapsulation part.
Extensibility can be achieved either by having a type implement multiple type classes, COM v1..vn style, or by delegation.
By your logic: 1. Ducks have feathers 2. All birds have feathers 3. Therefore, all birds are ducks
In any case, Haskell didn't get its polymorphism from any OOP language, so the point is moot. ML was first to introduce parametric polymorphism in 1975 — Java/C#/etc with their "generics" came later. Even ad hoc polymorphism with type classes was proposed 7 whole years (1988) before Java was even released (1995). And sure, the paper mentions that OOP has to solve similar issues, but "solving the same problem" ≠ "being the same solution".
> They surely do
That misses the point. The original challenge was
> > Can you name a contemporary expert or a platform that started or spent a good chunk of time as FP and ran back towards OOP
and didibus offered
> Hum, I think most did ... Haskell added TypeClasses
But that's simply not true that Haskell added type classes as an attempt to run back to OOP.
For example, OO has polymorphism as a core idea. TypeClasses are an implementation of ad-hoc polymorphism. This concept is a core part of OOP as well as all practical FP languages.
Now if we talk about OOP being bad, and we start talking about ad-hoc polymorphism. That's actually a great concept. It's one of the best concepts to appear in programming languages. So here we are talking about something great which most OOP languages have and make a core part of their offering. Something which Haskell also has and makes a core part of its offering.
Now you can try to move the goalpost, say nah, OOP doesn't mean ad-hoc polymorphism... okay what does it mean then? And maybe you mention class inheritance. Okay, is that it? What about abstraction, data encapsulation, overloading, access scopes, data instantiation, polymorphism, message passing, information hiding, actor-concurency, user defined types, etc. ?
So if you meant to say that inheritance is bad, then say that inheritance is bad. But even here, TypeClasses support inheritance?
> Haskell also supports a notion of class extension. For example, we may wish to define a class Ord which inherits all of the operations in Eq. [...] Note the context in the class declaration. We say that Eq is a superclass of Ord (conversely, Ord is a subclass of Eq), and any type which is an instance of Ord must also be an instance of Eq.
From: https://www.haskell.org/tutorial/classes.html
So what now? Maybe we actually mean that field inheritance is bad? Or what is it? And that's the kind of technicalities we should be discussing, not just say OOP bad, FP good.