There is, of course, clearly an ancestor / descendant relationship, but it needs not be semantic - subclassing mixes the two, at least in languages like scala and java, but it’s not a necessity. C++ has inheritance without subtyping, java subtyping without inheritance
But I'm not sure I see that as a flaw of subtyping. If you need a particular type, then you must provide an instance of that type, or a subtype. It's a clear contract, defined in terms of properties. If your value doesn't conform to that type then it's not meant to be used there.
-
-
You have other, more flexible ways to do that than nominal subtyping though. Type classes come to mind.
-
Yes, but even they can take advantage of subtyping. All I mean to say is that subtyping is quite simple, and does what it's meant to. And typeclasses take advantage of the way subtyping works to enable ad-hoc polymorphism. I don't see the flaw in subtyping.
- Show replies
New conversation -
Loading seems to be taking a while.
Twitter may be over capacity or experiencing a momentary hiccup. Try again or visit Twitter Status for more information.