-
-
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
eltype
inference for Iterators.map
could be more precise
#56891
Comments
The issue may be that the purpose of On the other hand, this also implies that users should, where possible, not rely on function simple_collect(it)
itval = iterate(it)
isnothing(itval) && return Union{}[]
(x, state) = itval
v = [x]
T = typeof(x)
itval = iterate(it, state)
while itval !== nothing
(x, state) = itval
if !isa(x, T)
T = typejoin(T, typeof(x))
v = T[i for i in v]
end
push!(v, x)
itval = iterate(it, state)
end
v
end Note that, if inference works well, all the "type stuff" done in this function will be compiled away. |
Thanks for your detailed explanation. |
Unfortunately, it's not entirely correct. There are some situations where using runtime types as I demonstrated above, is impractical. I can't really think of any, but I remember I've encountered them. Let's leave this issue open. Crossref: #56683 |
Your premise is false. Type inference is not supposed to be involved in the implementation of |
That said, it's possible to make Doesn't help with your example above, but it could be useful in limited cases. |
Thank you all for your detailed explanations and time. I now understand the purpose of |
I am puzzled on why
eltype
does not infer more precisely forIterators.map(f, iterators...)
, especially when both theeltype
of the input iterators and the return type off
seem to be inferable.Would it be possible to improve the
eltype
inference forIterators
.This enhancement could help improve type stability and make
Iterators.map
more consistent with the inferred types of other Julia constructs.The text was updated successfully, but these errors were encountered: