On Wednesday, November 5, 2014 10:01:10 AM UTC+11, [email protected] wrote:
>
> Bug map works fine...
>
> julia> g(x) = 1 / (1 + x)
> g (generic function with 1 method)
>
> julia> xs = [1.0, 2.0, 3.0, 4.0]
> 4-element Array{Float64,1}:
> 1.0
> 2.0
> 3.0
> 4.0
>
> julia> gxs1 = map(g, xs)
> 4-element Array{Float64,1}:
> 0.5
> 0.333333
> 0.25
> 0.2
>
>
Map determines the type dynamically at runtime. Comprehensions infer the
type at compile time, but the type of g(x) is dependent on the type of x,
so its not known at compile time.
If you define g(x) = (1/(1+x))::Float64 so the type of g(x) is known at
compile time then you get:
julia> gxs = [g(x) for x in xs]
4-element Array{Float64,1}:
0.5
0.333333
0.25
0.2
[...]
>
>>
>>