Are you doing this in the REPL, or inside a function? Type inference isn't 
great in the global scope, at least partly because Julia can't know that 
the types won't change in the future, and therefore can't make as tight 
inferences as it would otherwise.

I tried wrapping your code in a function, but to my surprise still got the 
same resutls:

```julia
julia> function foo()
       v = mapslices(var,randn(1000,3,19),[1])
       [v[1,1,j] for j = 1:19]
       end
foo (generic function with 1 method)

julia> foo()
19-element Array{Any,1}:
 0.994972
 0.961816
...
```

A quick-fix is easy - just annotate the element type:

```julia
julia> v = mapslices(var,randn(1000,3,19),[1]); eltype(v)[v[1,1,j] for j = 
1:19]
19-element Array{Float64,1}:
 0.969605
 1.00223 
...
```

but I don't think this should be needed inside a function. Someone more 
knowledgeable will have to expand on the details here.

// T

On Wednesday, July 16, 2014 11:08:31 AM UTC+2, Tomas Krehlik wrote:
>
> I came across a behavior that leaves me a bit puzzled, here is example: 
> v = mapslices(var,randn(1000, 3, 19), [1])
> [v[1,1,j] for j=1:19]
> I would expect the resulting Vector to be Float64, not Any. Can anybody 
> tell me if I am doing something wrong or why it should be expected to be 
> Any?
>
> Thanx.
>
>

Reply via email to