3 ms·
Not really. The goals of OO features such as method overriding is accomplished by typeclasses or implicits in FP. It's just that the default polymorphic mecha
by platz 10y ago
Not really.
The goals of OO features such as method overriding is accomplished by typeclasses or implicits in FP.
It's just that the default polymorphic mechanism for FP is parametric polymorphism, and the default mechanism for OO is ad-hoc polymorphism.
OO didn't have parametric polymorphism initially, and added it with Generics.
FP didn't have ad-hoc polymophism initially, and added it later with typeclasses or implicits.
Choosing OO or FP really just puts you one of the two side of the https://en.wikipedia.org/wiki/Expression_problem https://en.wikipedia.org/wiki/Expression_problem . They are more complimentary than proper subsets of each other.
- mafribe 10y agoI agree that implicits and type-classes can provide ad-hoc polymorphism, but I'm not aware that they have been reduced completely to FP without them, I'm also not aware of implicits and type-classes working in an untyped setting. If you have references to the contrary, I'd be interested to hear about it.
- platz 10y agoWell if one is looking for proofs, I think this is hard while remaining abstract from specific languages. I could counter that support for parametric polymorphism is poor in OO langs as much as you claim support for ad-hoc polymorphism is poor in FP langs. (but I don't place much stock in any of the aforementioned claims outside of some kind of artifical, academic context) Real-world problems that aren't an academic edge-cases will be supported by both FP and OO. Multimethods give you ad-hoc polymorphism in an uptyped setting.
- mafribe 10y agoParametric polymorphism is a concept that is orthogonal from the FP/OO distinction. You can define parametric polymorphism for parallel computation for example.