On Sat, Sep 24, 2016 at 8:54 PM, Steven G. Johnson <[email protected]>
wrote:

>
> julia> (begin;println(t);t^2;end for t=1:10)
>> Base.Generator{UnitRange{Int64},##37#38}(#37,1:10)
>>
>
> Julia knows that the input to the generator is a UnitRange{Int64}, i.e.
> 1:10, so the input elements are Int64.   It knows that the function being
> computed is t -> t^2.   The compiler is smart enough that it can figure out
> that if t is an Int64, then t^2 is an Int64 too, because that function is
> type stable.   So, it can figure out that the eltype of the output (i.e.
> the Generator) is Int64, all at compile time without actually evaluating
> the function.
>

It just feels like magic. Thank you for the explanation.

Reply via email to