-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Implement traits Iterable and Callable #34535
Comments
Possible duplicate: #23429. |
|
Seems like this would be a breaking change, unless |
For addressing this specific case --- giving a better error message --- something much simpler would suffice. If we make But, understanding the implications of method errors is critical to understanding how the language works. While traits might be very useful and indeed could be part of the future of the language, it's questionable whether adding a complex language feature truly ameliorates the confusion here. If you get a confusing error when trying to call |
It does not seem to work with function-like objects? julia> struct A end
julia> A isa Base.Callable
true
julia> (::A)() = 1
julia> a = A()
A()
julia> a isa Base.Callable
false |
Correct. Since any object is callable this way, that would make |
OK, based on the responses in this thread:
So it seems to be not possible to make these traits practically useful barring some complete redesign of how traits work in Julia, which is something outside the scope of this issue anyway. Closing the issue. |
Consider a Julia neophyte trying to sort
Char
s:Of course they should have used
max
. But that stack trace is long and confusing, considering that already the very first callmaximum(::Char, ::Char)
, the types are all wrong formaximum
. Normally, Julia methods have a signature that takes only appropritate abstract types, likeNumber
and so on, precisely so that the method only apply to inputs of the correct types.The problem is that there are no types for
Callable
orIterable
, so the signature ofmaximum
is totally untyped:maximum(f, a) = mapreduce(f, max, a)
.To solve this, I suggest implementing Holy traits
Iterable
andCallable
:One argument against doing this is that it could open the door to all kinds of traits in Base for this or that property. However, in my experience, it seems like the properties "iterable" and "callable" are particularly often used, just consider the amount of confusion about what is iterable or not we often see.
The text was updated successfully, but these errors were encountered: