My proposition works just as expected in your example. We match not the tail of scope sequence but the latest subsequence. Let me try to explain it again.
Consider we have a sequence like G, A1, B, C, A2
. Now we have a few functions, which will be bound to this scope:
-
[A].
will be bound because we haveA
in the sequence. It is not the last, but it does not matter. -
[A, B].
and[A, B, C].
will be bound for the same reason. -
[C, A].
will be bound because we have a subsequence ofC, A2
. -
[C, B].
won’t be bound because the order mismatch (if we stick to order-based approach). -
[A, B, A].
also won’t bind because you do not have secondA
, you will have to explicitly saya.doSomething()
for it to work.
So, as you see, all the classics work as you expect, the only confusion arises when you have some complicated cases with repeating types.