You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I think it currently just loops over the classes in each member of the union, which would be depth-first, but I agree breadth first does seem to make the most sense.
Also I don't think there is currently any check for duplicate classes, so R7_object probably currently gets registered twice, with the second registration overwriting the first.
Not sure I understand this question. We wouldn't have an instance of a union, right? Is this for methods with a union in their signature? But wouldn't they have equal affinity for each member of the union?
But I guess the problem only occurs if you mix dispatch on unions with dispatch on classes, so we might be able resolve this by warning when you override an existing method?
Ok, I'll have to think about how to implement that; currently defining a method for a union just defines methods for the individual classes.
That also raises the general question of what happens when you override an existing method. Currently it is silently overridden — that's probably what you want for interactive development, but not what you want when loading multiple packages.
On Mon, 13 Dec 2021, Hadley Wickham wrote:
Ok, I'll have to think about how to implement that; currently defining a
method for a union just defines methods for the individual classes.
That also raises the general question of what happens when you override an
existing method. Currently it is silently overridden — that's probably what
you want for interactive development, but not what you want when loading
multiple packages.
Dylan used to have the concept of marking various things as
'sealed'. That may be worth considering.
library(R7)
foo <- new_class("foo")
bar <- new_generic("bar", signature = "x")
method(bar, foo) <- function(x, ...) 1
method(bar, foo) <- function(x, ...) 2
bar(foo())
#> [1] 2
Created on 2021-12-13 by the reprex package (v2.0.1)
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub, or unsubscribe.
Triage notifications on the go with GitHub Mobile for iOS or Android.[AA55UVETDP6UWUAXEPMC7IDUQYOAVA5CNFSM5H6YBGDKYY3PNVWWK3TUL52HS4DFVREXG43VMV
BW63LNMVXHJKTDN5WW2ZLOORPWSZGOHMVL5ZY.gif]
In R7, method dispatch for unions is handled at method registration time, rather than at method dispatch time like S4. I think this approach is a bit simpler because it means that creating a R7 union does not affect the class hierarchy of existing R7 classes in the way that creating a S4 union does. This means that we can't prefer explicit classes over unions in general.
For now, I've added a message so that you at least know when you're overriding a method, and we can revisit sealing in the future.
Activity
jimhester commentedon Nov 15, 2021
I think it currently just loops over the classes in each member of the union, which would be depth-first, but I agree breadth first does seem to make the most sense.
jimhester commentedon Nov 15, 2021
Also I don't think there is currently any check for duplicate classes, so R7_object probably currently gets registered twice, with the second registration overwriting the first.
lawremi commentedon Nov 25, 2021
Not sure I understand this question. We wouldn't have an instance of a union, right? Is this for methods with a union in their signature? But wouldn't they have equal affinity for each member of the union?
hadley commentedon Nov 25, 2021
Right, in method dispatch, unions are a shortcut, so instead of writing (e.g.)
You can write:
But I guess the problem only occurs if you mix dispatch on unions with dispatch on classes, so we might be able resolve this by warning when you override an existing method?
lawremi commentedon Dec 13, 2021
Or we just define a rule that a method for a member of a union takes precedence over a method for that union.
mmaechler commentedon Dec 13, 2021
Yes, this would really intuitive, notably for people who already know the traditional S3 and S4 group methods.
hadley commentedon Dec 13, 2021
Ok, I'll have to think about how to implement that; currently defining a method for a union just defines methods for the individual classes.
That also raises the general question of what happens when you override an existing method. Currently it is silently overridden — that's probably what you want for interactive development, but not what you want when loading multiple packages.
Created on 2021-12-13 by the reprex package (v2.0.1)
ltierney commentedon Dec 13, 2021
hadley commentedon Feb 24, 2022
In R7, method dispatch for unions is handled at method registration time, rather than at method dispatch time like S4. I think this approach is a bit simpler because it means that creating a R7 union does not affect the class hierarchy of existing R7 classes in the way that creating a S4 union does. This means that we can't prefer explicit classes over unions in general.
For now, I've added a message so that you at least know when you're overriding a method, and we can revisit sealing in the future.
Inform when overwriting a method