User loginNavigation |
Multimethods over structural typesHello, I am interested to know if there are languages out there, or research projects, or people's wild private imaginings, that provide polymorphic multimethods over structural types. I mean the non-parametric type of polymorphism where methods may have > 1 implementation. The dispatch mechanism would choose the most specific of those available for a given invocation. I have found one mention of something that seems in this area, but I don't understand the paper enough to know if it's what I hope for: Combining Structural Subtyping and External Dispatch I'm not _even_ a language design noob, and have only recently found there is established terminology ("structural types") for what I've been edging towards for about 10 years. But… I envisage that the dispatch mechanism would be able to examine implementations of a method for the signature they require of their arguments. Given a method invocation is would be able to find the most specific implementation given the types, or fail if there is no match or the match is ambiguous. I also think that a kind of transitive closure is necessary here. I'll use an example to elucidate (the example is "single dispatch", btw):
def area(shape) # implementation 2 def width(shape) def height(shape) I can now evaluate: area( {radius: 1} ) area( {square_size: 2} ) Implementations's parameters are not decorated with explicit type declarations because the type an implementation needs for each of its arguments _are_ the methods it calls on those arguments. So, if this kind of thing is going on all over the place and well known, I'd love to know. Or if it's been tried and found a terrible idea, that'd be good to know too :-) I find the possibility enormously exciting because I think it'd "fix" an awful lot of what I find rather hobbling about the languages I generally use. Especially if it could be embedded in some kind of live-coding environment. Thanks, By Benjohn Barnes at 2014-03-13 22:06 | LtU Forum | previous forum topic | next forum topic | other blogs | 8475 reads
|
Browse archives
Active forum topics |
Recent comments
22 weeks 6 days ago
22 weeks 6 days ago
22 weeks 6 days ago
45 weeks 16 hours ago
49 weeks 2 days ago
50 weeks 6 days ago
50 weeks 6 days ago
1 year 1 week ago
1 year 6 weeks ago
1 year 6 weeks ago