Skip to main content
14 events
when toggle format what by license comment
Oct 22 at 22:45 history edited Jeff Walker Code Ranger CC BY-SA 4.0
deleted 1 character in body
Oct 22 at 22:42 comment added Jeff Walker Code Ranger Different languages handle multimethods differently. I chose a particular handling that would force safe equality. Some languages do allow a multimethod to match all subtypes of its parameters. Some languages have a way to do what I have said. No, it doesn't violate Liskov substitution because of multiple dispatches. Think of it as being like a visitor pattern where you are required to implement every case. It is just saying the multimethod must be overriden for each type.
Oct 22 at 22:33 comment added kaya3 So if I understand correctly, a multimethod defined for a parameter of type T does not work on an argument of type S where S < T. Is that not a clear violation of the Liskov substitution principle?
Oct 22 at 22:31 comment added Jeff Walker Code Ranger Yes, this approach does not work well for a language with universal equality.
Oct 22 at 22:30 history edited Jeff Walker Code Ranger CC BY-SA 4.0
Giving an alternative psuedocode syntax to maybe clarify.
Oct 22 at 22:30 comment added MisterMiyagi @JeffWalkerCodeRanger Well, those can still be a lot. But more critically, in languages that have a common base type (think Object in Java or Python) or expect equality to be universal these are still all types.
Oct 22 at 22:26 comment added Jeff Walker Code Ranger @MisterMiyagi I've clarified that it is every pair of types that are a subtype of the base type. So in this example, every pair of subtypes of type Point must somehow be covered.
Oct 22 at 22:24 comment added Jeff Walker Code Ranger No @kaya3, ==(Point p1, Point p2) is not considered to cover every pair of types in my pseudocode because it should be called only when both parameters are Point and not subtypes to satisfy the multiple dispatch. Don't think of these as static overloads or simple overrides. (I've added a comment to try to clarify).
S Oct 22 at 22:21 review First answers
Oct 23 at 0:56
S Oct 22 at 22:21 history edited Jeff Walker Code Ranger CC BY-SA 4.0
Clarifying answer based on comments
Oct 22 at 22:03 comment added MisterMiyagi "the compiler will statically enforce that the equality of every pair of types must be covered" This sounds excessive. Most pairs of types aren’t meaningful to compare (or trivially unequal if one insists) yet there are a lot of them.
Oct 22 at 21:55 comment added kaya3 Doesn't the first declaration, ==(Point p1, Point p2), already cover every pair of types, and the others are just overrides?
S Oct 22 at 21:47 review First answers
Oct 22 at 22:19
S Oct 22 at 21:47 history answered Jeff Walker Code Ranger CC BY-SA 4.0