For tuples, it seems mapreduce
has poorer type inference than map
+ reduce
.
julia> using FillArrays, Infinities, InfiniteArrays, Test
julia> ax = Ones{Int}(InfiniteCardinal{0}());
julia> y = (ax,ax);
julia> @inferred (t -> mapreduce(sum, *, t))(y)
ERROR: return type InfiniteCardinal{0} does not match inferred return type Any
Stacktrace:
[1] error(s::String)
@ Base ./error.jl:35
[2] top-level scope
@ REPL[6]:1
julia> @inferred (t -> reduce(*, map(sum, t)))(y)
ℵ₀
This is perhaps because map
is specialized for tuples. Is this an instance where code_warntype isn’t accurate, and the result is correctly inferred in both cases? Or is it better to replace mapreduce
by map
+ reduce
?