3 ms·
ah thanks for your reply, it seems a sensible system. A last question (since when I tried to wrap my head around multimethods, OOP and modules for my toy langu
by riffraff 15y ago
ah thanks for your reply, it seems a sensible system.
A last question (since when I tried to wrap my head around multimethods, OOP and modules for my toy language I always got lost and you probably have an answer).
Suppose I want to define a method local to an object in my main module, for example I want to have Dates#weeks use a custom #singular method.
For sake of polymorphism, I would expect that dispatching on my object should still invoke my method, but weeks is always referring to its own, I understand.
Do you believe this trade off (killing a bit of late binding, akin to having un-overrideable "private" members in java/c++) is necessary, or you just feel this is a good enough solution?
- munificent 15y ago> I would expect that dispatching on my object should still invoke my method, but weeks is always referring to its own, I understand. Correct. But if singular itself was publicly exported by Dates, when you defined your own specializations of it in your module, they will go into the same multimethod that Dates is using. The big limitation here is that you can't replace the version that Dates has specialized on String by specializing on the same type. The way this works is that when you import a multimethod from another module, you're importing the exact same multimethod object that that module is using. If you then define your own specializations, the original module can see them too. This is necessary to make overriding work at all, though it's a bit confusing in some ways. Honestly, I feel like I'm still trying to wrap my head around it too.