4 ms·
All of them. But the one I like the most is Parametric polymorphism because it tends to make algorithms generically available to anything. And the one I like
by zaphar 12y ago
All of them.
But the one I like the most is Parametric polymorphism because it tends to make algorithms generically available to anything.
And the one I like the least is subtype polymorphism due to it's reliance on inheritance with all it's attendant problems. The exception being for the sub-genre of "interface" polymorphism. Which doesn't really exist in C++. However when it does exist such as in languages like Go, Java, or C# then it fixes almost all of the problems that tradional subtype polymorphism has by taking inheritance completely out of the picture.
- haifeng 12y agoAgree. I like most parametric polymorphism too. The drawbacks are: 1. In C++, the compile error messages with templates are so hard to navigate. 2. In OCaml, sometimes we need pay attentions on the performance.
- ufo 12y agoparametric polymorphism also give you "theorems for free" if you choose the right places to put your abstractions.
- panic 12y agoOCaml models "interface" polymorphism using an extension to parametric polymorphism called row polymorphism (https://realworldocaml.org/v1/en/html/objects.html https://realworldocaml.org/v1/en/html/objects.html), which lets you avoid subtyping even for interface types.