Discussion Thread: DIP 1037--Add Unary Operator ...--Community Review Round 1

Ola Fosheim Grøstad ola.fosheim.grostad at gmail.com
Wed Oct 28 17:52:41 UTC 2020


On Wednesday, 28 October 2020 at 17:48:21 UTC, Paul Backus wrote:
> The library author could just as easily use `T.init` as the 
> initial value, and if the code is never tested with floats, it 
> will appear to work just fine. So requiring an initial value 
> does nothing to prevent this hypothetical bug.

No, it is common to fold with 0 for addition and 1 for 
multiplication. Anyone that has some programming background will 
use that when the think about initial value.

Or "zero" and "identity", which in my view should be traits for 
numbers. In my own lib for generic programming I use those. Then 
you can write generic code that work for matrices etc.



More information about the Digitalmars-d mailing list