Right; to some extent it’s ok to use the inferred type, as long as your code is fine with it being
Any. It’s safe to use as a hint, like a size hint. For example I can imagine other implementations of Julia, or other execution environments, where
return_type just always returns
Any so that the type inference code doesn’t have to be included. But in my experience most people are not fine with
Any; they have a more specific type in mind they’d like to get.
Inferred types do not have to get more specific over time, as the compiler improves, either. In fact at this very moment I am hoping to make many inferred types worse to speed up the compiler. Learn to love
Any; it’s efficient to deduce!
The OP has an interesting point: since we have
IteratorEltype anyway, we could potentially return
HasEltype for generators when, say,
return_type is a concrete type. Of course, then people would have to be ok with
IteratorEltype being unpredictable the same way