Sent from my iPhone
> On Jan 25, 2017, at 1:45 PM, David Sweeris via swift-evolution
> <swift-evolution@swift.org> wrote:
>
>
>> On Jan 25, 2017, at 10:03, Xiaodi Wu via swift-evolution
>> <swift-evolution@swift.org> wrote:
>>
>> Stephen Canon wrote that Arithmetic should refine
>> ExpressibleByIntegerLiteral because of certain mathematical properties of
>> rings. In that case, 0 and 1 would just be spelled in that way. Otherwise,
>> +1.
>>> On Wed, Jan 25, 2017 at 11:38 Anton Mironov via swift-evolution
>>> <swift-evolution@swift.org> wrote:
>>> Hi everyone,
>>>
>>> I want to suggest a tiny extension to an Arithmetic protocol. It would be
>>> nice to have an additive identity and a multiplicative identity constants.
>>> Basically zero and one.
>>>
>>> ```
>>> protocol Arithmetic {
>>> /* ... */
>>> static var zero: Self { get } // additive identity: (value + .zero) ==
>>> value
>>> static var one: Self { get } // multiplicative identity: (value * .one)
>>> == value
>>> }
>>> ```
>>>
>>> These constants will ease implementation of math structures: vectors,
>>> matrices and etc.
>>> I’m sorry if I’m duplicating someone’s suggestion. It is really hard to
>>> search for something in a long thread.
>
> There is some merit in having them be declared as static properties... If
> it's a non-trivial process to initialize a type, it might be worth it to have
> a static property that either provides the storage directly or just returns a
> fileprivate value declared outside the type.
A type for which this was necessary can just special-case handling 0 and 1
literals.
_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution