Friday 11 March 2016

Julia: Method overloading ambiguities

If you don’t overload methods in unique way, it leads to ambiguities.


For example,
julia> function process_data(num1, num2::Float64)
           num1+num2
       end
process_data (generic function with 1 method)

julia> function process_data(num1::Float64, num2)
           num1+num2
       end
WARNING: New definition 
    process_data(Float64, Any) at none:2
is ambiguous with: 
    process_data(Any, Float64) at none:2.
To fix, define 
    process_data(Float64, Float64)
before the new definition.
process_data (generic function with 2 methods)


Observe above code snippet, when I try to define process_data method in ambiguous way, Julia throws warning, but it allows second method to proceed.
julia> methods(process_data)
# 2 methods for generic function "process_data":
process_data(num1, num2::Float64) at none:2
process_data(num1::Float64, num2) at none:2



Previous                                                 Next                                                 Home

No comments:

Post a Comment