5 ms·
> I'm pretty sure is what the author meant. Clearly not considering he mentions typeclass in the article. Module signatures are similar to interface and param
by WastingMyTime89 3y ago
> I'm pretty sure is what the author meant.
Clearly not considering he mentions typeclass in the article.
Module signatures are similar to interface and parametrized modules allow you to do what you would do with abstract class: you define a signature and then write a module using these functions. Parametrized modules are more or less a generalization of functions which goes from module to module.
- arc-in-space 3y agoSorry, I initially wrote 'interfaces as in OOP' to distinguish them from module interfaces, but had 'ad-hoc polymorphism' in mind. 'interfaces' is much too overloaded of a term.
- WastingMyTime89 3y agoOcaml has no ad-hoc polymorphism but you can use parametrised modules to write generic code which you will have to specialise at some point. That brings you ninety percents of the way in term of what ad-hoc polymorphism is used for. It's more cumbersome but I prefer it to the complexity involved by what Scala does for exemple.
- ywei3410 3y agoWould you not consider the object system to be ad-hoc polymorphism?
- octachron 3y agoThe OCaml object system is still parametric polymorphism (trying to pass itself as subtyping polymorphism through row variables) rather than ad-hoc polymorphism: there are still no functions that only work on a finite subset of types. In other words, a function may work on any objects that has a method `m`, but you cannot have the same method that has different implementation for `int` and `float`.
- WastingMyTime89 3y agoIt uses structural typing not ad-hoc polymorphism. Plus it’s rarely used and it used to give hard to parse error messages when you made type mistakes. I don’t really see it as an adequate replacement for ad-hoc polymorphism.