[julia-users] Re: Dictionary type inference

2016-10-13 Thread Steven G. Johnson
I've filed an issue for further 
discussion: https://github.com/JuliaLang/julia/issues/18906


[julia-users] Re: Dictionary type inference

2016-10-13 Thread Steven G. Johnson
No, promote_type is working.

I think this is intended behavior: if you construct a Dict with keys and/or 
values of different types, then it will default to using Any.  For example:

julia> Dict(3=>4, 3.5=>4.5)

Dict{Any,Any} with 2 entries:

  3   => 4

  3.5 => 4.5


This was true in Julia 0.4 as well.   In Julia 0.5, now that functions have 
their own types, Dict(sin=>sin, cos=>cos) also produces Any.

I wonder whether the Dict constructor should use the typejoin of its 
entries instead?


[julia-users] Re: Dictionary type inference

2016-10-13 Thread Michele Zaffalon
With one element only, type inference gives:

julia> typeof(Dict(sin => sin))
Dict{Base.#sin,Base.#sin}


On Thursday, October 13, 2016 at 9:26:37 AM UTC+2, David van Leeuwen wrote:
>
> Hello, 
>
> I have stumbled across the following type inference issue for `Dict`s in 
> julia-v0.5:
>
> julia> typeof(Dict(sin => sin, cos => cos))
>
> Dict{Any,Any}
>
> julia> typeof(Dict(x => x for x in [sin, cos]))
>
> Dict{Function,Function}
>
> In Julia-0.5, functions got their own type.  I was surprised to see that 
> the type inference in the `Dict(:a => sin, :b => cos)` for the value of the 
> dict is `Any` and not `Function`.  In the comprehension syntax, the type of 
> the value _is_ generalised to `Function`.  
>
> Is this intended behavior?
>
>
>