-
-
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
[f(x) | x=y] not the same as map(f, y) #670
Comments
Looks like another head of the hydra that is issue 524. (Edited to delink; see below.) |
No, this is actually a completely different issue and one of the most deep and vexing problems with Julia's approach to types. The problem is that in general we have semantics that only depend on run-time types, not on anything that the compiler can infer about types. However, we also store arrays with concrete element types like The problem comes in when you want to map or comprehend and need to know what map(f, v) or [ f(x) | x=v ] ? In a statically typed language, the compiler has to be able to completely determine the type behavior of map(x->2x+1, [0:9]) The expression
The first option sucks because you either end up storing the computed values in some inefficient intermediate location, or computing them all twice! The second option is what we're currently doing for The third option is the best, but it still sucks. Here's why: it makes program semantics depend on type inference — which is, in every other circumstance, just a heuristic that speeds programs up without changing their behavior. Suppose I have a situation where Jeff and I have talked about this a lot, especially over the past few days while we were at Lang.NEXT. I think we have worked out a way to do this that will be practical and make sure that programs that work will continue working even when the type inference is improved. Basically, the conservative thing to do here is to throw an error if the type inference can't determine a tight bound on the element type — and have the same behavior for both |
I should really use more question marks. Thanks for the detailed comment. I've edited my first comment to delink. |
duplicate of #210. |
* Base.hash for test statistics * woops, simple equality
typeof(map(x -> x^2, [1,2,3])) = Array{int64,1}
typeof([ x^2 | x=[1,2,3]) = Array{Any, 1}
It seems odd that the comprehension loses the type information, while map retains it.
The text was updated successfully, but these errors were encountered: