3 ms·
Dynamic dispatch is not syntactic sugar for a if-cascade. It is normaly implemented via vtables. If you try to do this in a language without polymorphism (e.g.
by beza1e1 17y ago
Dynamic dispatch is not syntactic sugar for a if-cascade. It is normaly implemented via vtables. If you try to do this in a language without polymorphism (e.g. C) you have to do this by hand and keep track of your vtable layout (third function pointer is 'evaluate' ...). Your example is nice to describe the effect of dynamic dispatch, but misleading about the mechanism.
Polymorphism is the core of OOP, which consequently means that Haskell is OO.
- jrockway 17y agoIt is normally implemented via vtables. OK, irrelevant. We are not discussing runtime implementation, we are discussing language semantics. A table lookup and a cascade of if statements are semantically the same. Value in, result out. Polymorphism is the core of OOP, which consequently means that Haskell is OO. You're going to have to explain this with more than one statement. "OOP" is a meaningless expression. "Haskell is OO" is similarly meaningless. My Haskell example shows that functions can be polymorphic over values. OOP is polymorphic over types. Haskell typeclasses provide polymorphism over classes of types. Not the same. But similar expressive power is possible either way.
- beza1e1 17y agoI don't think OOP is meaningless. It's just diffused by too much talking. For me OOP essentially means polymorphism and here is an article i wrote about that: http://beza1e1.tuxen.de/articles/oop.html http://beza1e1.tuxen.de/articles/oop.html My Haskell knowledge is superficial so i'll keep my mouth shut about the various kinds of polymorphism you describe.
- cema 17y ago"For me OOP essentially means" etc: that's the key. OOP means different things to different people. So the term is confusing and people who seek clarity want to avoid it.
- deleted 17y ago[deleted]