Re: [julia-users] Re: getting a warning when overloading +(a,b)

2016-04-02 Thread Gerson J. Ferreira
Ok. I'm reading again the Modules section of the manual. Now I understand
better the difference between import and using. Thanks.
On Apr 2, 2016 1:27 PM, "Kristoffer Carlsson"  wrote:

> Because you want to overload a function from Base.


[julia-users] Re: getting a warning when overloading +(a,b)

2016-04-02 Thread Kristoffer Carlsson
Because you want to overload a function from Base.

[julia-users] Re: getting a warning when overloading +(a,b)

2016-04-02 Thread Gerson J. Ferreira
Thanks! But why do I need to import Base.+? 

Em sexta-feira, 1 de abril de 2016 12:02:13 UTC-3, Giuseppe Ragusa escreveu:
>
> ```
> import Base.+
> type numerr
> num
> err
> end
>
> +(a::numerr, b::numerr) = numerr(a.num + b.num, sqrt(a.err^2 + b.err^2));
> +(a::Any, b::numerr) = numerr(a + b.num, b.err);
> +(a::numerr, b::Any) = numerr(a.num + b, a.err);
>
> x = numerr(10, 1);
> y = numerr(20, 2);
>
> println(x+y)
> println(2+x)
> println(y+2)
> ```
>
>
>
> On Friday, April 1, 2016 at 4:51:53 PM UTC+2, Gerson J. Ferreira wrote:
>>
>> I'm trying to overload simple math operators to try a code for error 
>> propagation, but I'm getting a warning. Here's a short code that already 
>> shows the warning message:
>>
>> type numerr
>> num
>> err
>> end
>>
>> +(a::numerr, b::numerr) = numerr(a.num + b.num, sqrt(a.err^2 + b.err^2));
>> +(a::Any, b::numerr) = numerr(a + b.num, b.err);
>> +(a::numerr, b::Any) = numerr(a.num + b, a.err);
>>
>> x = numerr(10, 1);
>> y = numerr(20, 2);
>>
>> println(x+y)
>> println(2+x)
>> println(y+2)
>>
>> I didn't see much about operator overloading in Julia's manual. I would 
>> really appreciate if someone could point me in the right direction.
>>
>> The code above returns this warning in Julia 0.4.2:
>>
>>_   _ _(_)_ |  A fresh approach to technical computing
>>   (_) | (_) (_)|  Documentation: http://docs.julialang.org
>>_ _   _| |_  __ _   |  Type "?help" for help.
>>   | | | | | | |/ _` |  |
>>   | | |_| | | | (_| |  |  Version 0.4.2 (2015-12-06 21:47 UTC)
>>  _/ |\__'_|_|_|\__'_|  |  Official http://julialang.org release
>> |__/   |  x86_64-linux-gnu
>>
>> julia> include("overload.jl")
>> WARNING: module Main should explicitly import + from Base
>> numerr(30,2.23606797749979)
>> numerr(12,1)
>> numerr(22,2)
>>
>>
>>

[julia-users] Re: getting a warning when overloading +(a,b)

2016-04-01 Thread Giuseppe Ragusa
```
import Base.+
type numerr
num
err
end

+(a::numerr, b::numerr) = numerr(a.num + b.num, sqrt(a.err^2 + b.err^2));
+(a::Any, b::numerr) = numerr(a + b.num, b.err);
+(a::numerr, b::Any) = numerr(a.num + b, a.err);

x = numerr(10, 1);
y = numerr(20, 2);

println(x+y)
println(2+x)
println(y+2)
```



On Friday, April 1, 2016 at 4:51:53 PM UTC+2, Gerson J. Ferreira wrote:
>
> I'm trying to overload simple math operators to try a code for error 
> propagation, but I'm getting a warning. Here's a short code that already 
> shows the warning message:
>
> type numerr
> num
> err
> end
>
> +(a::numerr, b::numerr) = numerr(a.num + b.num, sqrt(a.err^2 + b.err^2));
> +(a::Any, b::numerr) = numerr(a + b.num, b.err);
> +(a::numerr, b::Any) = numerr(a.num + b, a.err);
>
> x = numerr(10, 1);
> y = numerr(20, 2);
>
> println(x+y)
> println(2+x)
> println(y+2)
>
> I didn't see much about operator overloading in Julia's manual. I would 
> really appreciate if someone could point me in the right direction.
>
> The code above returns this warning in Julia 0.4.2:
>
>_   _ _(_)_ |  A fresh approach to technical computing
>   (_) | (_) (_)|  Documentation: http://docs.julialang.org
>_ _   _| |_  __ _   |  Type "?help" for help.
>   | | | | | | |/ _` |  |
>   | | |_| | | | (_| |  |  Version 0.4.2 (2015-12-06 21:47 UTC)
>  _/ |\__'_|_|_|\__'_|  |  Official http://julialang.org release
> |__/   |  x86_64-linux-gnu
>
> julia> include("overload.jl")
> WARNING: module Main should explicitly import + from Base
> numerr(30,2.23606797749979)
> numerr(12,1)
> numerr(22,2)
>
>
>