In the package I am contributing to, I would like to use Base.promote_op
to infer the return type of an arbitrary function given by users. For example, if I want to know the return type of sin(x)
for x::Int64
, I can do
julia> Base.promote_op(sin, Int64)
Float64
However, if the function’s name is a type name, I get a deprecation warning:
julia> VERSION
v"0.6.1-pre.0"
julia> Base.promote_type(Float64, Int64)
WARNING: promote_op(op::Type, ::Type...) is deprecated as it is no longer needed in Base. If you need its functionality, consider defining it locally.
Stacktrace:
[1] depwarn(::String, ::Symbol) at ./deprecated.jl:70
[2] promote_op(::Type{T} where T, ::Type{T} where T) at ./deprecated.jl:399
[3] eval(::Module, ::Any) at ./boot.jl:235
[4] eval_user_input(::Any, ::Base.REPL.REPLBackend) at ./REPL.jl:66
[5] macro expansion at ./REPL.jl:97 [inlined]
[6] (::Base.REPL.##1#2{Base.REPL.REPLBackend})() at ./event.jl:73
while loading no file, in expression starting on line 0
Float64
Here, Float64
is used as a function (like sin
in the earlier example) rather than a type, because in many cases type names double as converter functions. In other words, the intent of the of the above code is to know the return type of the function Float64(x)
for x::Int64
. Still, Julia 0.6 deprecates such usage of promote_op
.
Then, what are the alternatives to promote_op
that works for any functions, including the ones whose names are type names? How is this situation handled in Base
? I tried to find examples in Base
and also searched through issues, but had a hard time finding relevant ones.