On Fri, Apr 1, 2016 at 5:33 AM, Tamas Papp <[email protected]> wrote:
> Hi,
>
> I ran into a problem with the result type of Dict comprehensions. If I
> wrap the comprehension in a function, it produces the narrowest type,
> otherwise the type of value is Any. Code looks like this:
>
> ## this version is not type stable, result of comprehension is a Dict
> ## with value type Any
> function proportions{Tv,Tk}(dt::DynamicTable{Tv,Tk}, dims::Vector{Int})
>     d = _remaining_dims(dt,dims)
>     e = dt.elements
>     s = sum(dt,dims).elements
>     DynamicTable([key => value/s[key[d]] for (key,value) in e],
>                  dt.ordering)
> end
>
> ## in this version, type of Dict's value is the correct type (eg a
> ## Float64 for Tv=Int)
> function proportions{Tv,Tk}(dt::DynamicTable{Tv,Tk}, dims::Vector{Int})
>     _proportions(e, s, d) = [key => value/s[key[d]] for (key,value) in e]
>     DynamicTable(_proportions(dt.elements, sum(dt,dims).elements, 
> _remaining_dims(dt, dims)),
>                  dt.ordering)
> end
>
> I realize the example is not self-contained, but if the issue is not
> something known and obvious and someone is willing to help me
> investigate, I can provide a link to the source (not terribly long, but
> longer than a snippet I could post here).
>
> VERSION v"0.4.6-pre+4".

https://github.com/JuliaLang/julia/issues/7258

>
> Best,
>
> Tamas

Reply via email to