Yes, that's just a missing optimization / feature of type inference.

I'd argue that it should be perfectly reasonable to capture bindings before
executing comprehensions – the theory being that comprehensions are
inherently parallel so any change to the binding of f shouldn't be visible
until after the comprehension is evaluated. Thus, you could interpret

[f(x) for x in [1,2,3]]


as

let f = f
  [f(x) for x in [1,2,3]]
end


This would actually make most of the type inference issues with
comprehensions disappear. We should probably do that.

On Mon, Feb 17, 2014 at 9:19 PM, Fil Mackay <[email protected]>wrote:

> On Tue, Feb 18, 2014 at 11:56 AM, Stefan Karpinski 
> <[email protected]>wrote:
>
>> Even if anonymous functions were exactly like named functions (they're
>> not), the non-constness of the bindings in your original example prevent
>> inlining, etc.
>>
>
> Yup. I added in const as well to remove this factor. I am left with types
> being dropped:
>
> julia> const f = i->i
> (anonymous function)
>
> # dropped types
> julia> [f(x) for x in [1,2,3]]
> 3-element Array{*Any*,1}:
>  1
>  2
>  3
>
> # but this one works?
>  julia> [(i->i)(x) for x in [1,2,3]]
> 3-element Array{*Int64*,1}:
>  1
>  2
>  3
>
> I'm assuming this is just the way it is for the time being (used named
> functions).
>

Reply via email to