4 ms·
Type classes are a way to do polymorphism, but... dynamic dispatch? I don't think so; which function is called, is determined statically. As for ML functors: t
by GrumpySloth 5y ago
Type classes are a way to do polymorphism, but... dynamic dispatch? I don't think so; which function is called, is determined statically.
As for ML functors: they're neither polymorphism, nor dynamic dispatch. First: functions for different types can't share names (unless we're talking about shadowing of names with lexical scope), the names are either qualified with the name of the struct they come from or they're not qualified at all. In all cases there is exactly one implementation for every name. And again: no dynamic dispatch. MLton even defunctorizes all code at compile-time. The only polymorphism in SML is the one that's used in some built-ins (like +), but it's not available to users of the language. SML has something called "polymorphic functions", but it has nothing to do with writing multiple implementations of one function under one name and letting the compiler select which one is called; which is what is usually meant by "polymorphism".
- pjmlp 5y agoThere are many ways to skin a cat how those declarations are written. If I have time later I might post an example, apparently we are only right with code.