The problem and a potential source of confusion is that the trait is named 
'Zero' when a more proper name would be 'AdditiveIdentity'. There could be 
separate trait to indicate zero, but I don't know how much value such a trait 
would have. Here's the formal definition of additive identity from wikipedia:

Let N be a set which is closed under the operation of addition, denoted +. An 
additive identity for N is any element e such that for any element n in N,

e + n = n = n + e
Example: The formula is n + 0 = n = 0 + n.


That's the reason it doesn't require the Mult trait.

> On 09 Apr 2014, at 11:18, Rémi Fontan <remifon...@yahoo.fr> wrote:
> 
> thanks for all your replies. I understand that zero has a specific meaning to 
> addition, and as well as multiplication, but for some reason does not require 
> the mul trait.
> 
> implementing default sounds like a reasonable solution for my case. I 
> initially wanted to implement zero for my matrix4x4. I haven't implemented 
> add as I don't think I'm going to be adding matrix so I did not bother. 
> making default return [0...0] would work as well.
> 
> cheers,
> 
> Rémi
> 
> 
> 
>> On Wed, Apr 9, 2014 at 5:20 AM, Kevin Ballard <ke...@sb.org> wrote:
>>> On Apr 7, 2014, at 1:02 AM, Tommi Tissari <rusty.ga...@icloud.com> wrote:
>>> 
>>>> On 07 Apr 2014, at 08:44, Nicholas Radford <nikradf...@googlemail.com> 
>>>> wrote:
>>>> 
>>>> I think the original question was, why does the zero trait require the add 
>>>> trait.
>>>> 
>>> If that was the original question, then my answer would be that 
>>> std::num::Zero requires the Add trait because of the way it is specified: 
>>> "Defines an additive identity element for Self". Then the question becomes: 
>>> "why is Zero specified like that?", and I would answer: because then you 
>>> can use it in generic algorithms which require their argument(s) to have an 
>>> additional identity. 
>> 
>> If you want a zero value for a type that doesn't support addition, 
>> std::default::Default may be a good choice to use. Semantically, that 
>> actually returns the "default value" for a type instead of the "zero value", 
>> but in a type without addition, how do you define "zero value"?
>> 
>> -Kevin
>> 
>> _______________________________________________
>> Rust-dev mailing list
>> Rust-dev@mozilla.org
>> https://mail.mozilla.org/listinfo/rust-dev
> 
> 
> 
> -- 
> Rémi Fontan : remifon...@yahoo.fr
> mobile: +64 21 855 351
> 93 Otaki Street, Miramar 6022
> Wellington, New Zealand
_______________________________________________
Rust-dev mailing list
Rust-dev@mozilla.org
https://mail.mozilla.org/listinfo/rust-dev

Reply via email to