<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head><body dir="auto"><div><br><br>Sent from my iPhone</div><div><br>On Jan 25, 2017, at 1:45 PM, David Sweeris via swift-evolution <<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>> wrote:<br><br></div><blockquote type="cite"><meta http-equiv="content-type" content="text/html; charset=utf-8"><div><span></span></div><div><meta http-equiv="content-type" content="text/html; charset=utf-8"><div><br></div><div>On Jan 25, 2017, at 10:03, Xiaodi Wu via swift-evolution <<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>> wrote:<br><br></div><blockquote type="cite">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.<br><div class="gmail_quote"><div dir="ltr">On Wed, Jan 25, 2017 at 11:38 Anton Mironov via swift-evolution <<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word" class="gmail_msg"><div class="gmail_msg">Hi everyone,</div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">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.</div><div class="gmail_msg"><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">```</div><div class="gmail_msg">protocol Arithmetic {</div><div class="gmail_msg"> /* ... */</div><div class="gmail_msg"> static var zero: Self { get } // additive identity: (value + .zero) == value</div><div class="gmail_msg"> static var one: Self { get } // multiplicative identity: (value * .one) == value</div><div class="gmail_msg">}</div></div><div class="gmail_msg">```</div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">These constants will ease implementation of math structures: vectors, matrices and etc.</div><div class="gmail_msg">I’m sorry if I’m duplicating someone’s suggestion. It is really hard to search for something in a long thread.</div></div></blockquote></div></blockquote><br><div>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.</div></div></blockquote><br><div>A type for which this was necessary can just special-case handling 0 and 1 literals.</div></body></html>