-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
make isa
a generic function
#37240
make isa
a generic function
#37240
Conversation
Hm, I'm not sure what's going on with these build errors. It built fine for me locally... |
Might be a difference in running with asserts enabled or not. |
One point of hesitation for me here is that this would allow people to overload |
See my comment #36759 (comment). |
Disallowing further overloading is table stakes for me not to veto this change. |
Ah, sorry I looked around for issues / PRs but was having trouble finding relevant search results, I didn't realize this was previously discussed. Should I close this PR as a duplicate? I will say that I have found myself in situations with packages like SymbolicUtils.jl where we wanted predicate functions The counterpoints raised are quite understandable though and I see the potential downsides. Here's one potential way to make this a win-win: what if I went through all the usage of
That would indeed be a great feature, but one that is beyond my ken 😅 |
|
It'd be the same object as far as the compiler is concerned, right? Edit: I realize now you're talking about if people used |
Not if there are enough When the result is used in an I'm against this change, too. |
But isn't the point exactly that it can now be overloaded so in the presence of non-precise type information, you (the compiler) have no idea what |
In such a case where that matters, couldn't we just recommend the package author use I guess at this point though if we're just going to end up using It's just unfortunate that |
No idea how robust it is or how easily it can be undone by a malicious user, but I've used Jameson's trick to stop people from being able to add methods to |
Okay, so I haven't yet figured out how to get _ _ _(_)_ | Documentation: https://docs.julialang.org
(_) | (_) (_) |
_ _ _| |_ __ _ | Type "?" for help, "]?" for Pkg help.
| | | | | | |/ _` | |
| | |_| | | | (_| | | Version 1.6.0-DEV.742 (2020-08-27)
_/ |\__'_|_|_|\__'_| | generic-isa/01e15fe6a1 (fork: 4 commits, 0 days)
|__/ |
julia> Base.isa(1, Int)
true
julia> Base.isa(Int)(1)
true
julia> Base.isa(x, y) = "boo!"
ERROR: cannot add methods to a builtin function
Stacktrace:
[1] top-level scope
@ REPL[3]:1 |
Currently,
isa
is a builtin function which causes various annoyances. For instance,and it also makes it so that we can't have a curried method
This PR simply makes generic function
Base.isa(x, T) = Core.isa(x, T)
and adds a curried methodisa(T) = Fix2(isa, T)
so that we can make functions likeisastring = isa(String)
.I think this is a nice, minor convenience that costs us little to add.
Fixes #32018