3 ms·
The statement author makes that polymorphism is belongs to OPP is incorrect. Functional languages by design require better type systems that can accommodate mo
by Avi-D-coder 8y ago
The statement author makes that polymorphism is belongs to OPP is incorrect.
Functional languages by design require better type systems that can accommodate more forms parametric polymorphism.
OPP traditionally encouraged the use of ad-hoc polymorphism (via classes) over parametric polymorphism (via generics). OPP languages generally also make it easy to perform Ad-hoc polymorphism at run-time with dynamic dispatch some languages even use dynamic dispatch by default.
TLDR: FP and OPP both have polymorphism.
FP encourages parametric polymorphism.
OPP encourages ad-hoc polymorphism.
- joel_ms 8y agoAd-hoc polymorphism is interfaces in java, typeclasses in haskell, implicits in scala etc. Classes (usually) enable subtype polymorphism.
- Avi-D-coder 8y agoI would argue that subtype polymorphism is functionally equivalent to Ad-hoc polymorphism especially in the presence of multiple inheritance. The distinction is how polymorphic code is written not what the semantics can be expressed. E.g. rust traits allow for dynamic dispatch. While there is a distinction between ad-hoc polymorphism and subtype polymorphism, I don't believe it is necessary when comparing what semantics FP and OPP languages express.