<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div><blockquote type="cite" class=""><div class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class=""><div class="">What this proposal is asking for is an easier way to have derived values from enum cases. Asking for more flexible RawValues means mass and radius are not derived, they are the source of truth. It goes against the whole point of RawRepresentable. You are not saying ‘Mercury is identified by the case .mercury’, you are saying ‘Mercury is identified by a mass of 3.303e+23’. It’s backwards.</div></div></div></div></blockquote><div><br class=""></div><div>I see what Janis meant in the first email. It's not that the planet would be identified by the mass or radius. It could very much be&nbsp;</div><div><br class=""></div><div>case Mercury = 1 where (mass: 3, radius: 2),</div><div><br class=""></div><div>- Mercury's rawValue would be 1.</div><div><br class=""></div><div>The issue here is that sometimes you want additional information with the enum. There are many cases where you extend the enum with a variable:</div><div><br class=""></div><div>enum Error {</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>case NoError</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>case FileNotFound</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>...</div><div><br class=""></div><div><span class="Apple-tab-span" style="white-space:pre">        </span>var isFatal: Bool {</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>/// swtich over all values of self goes here.</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>}</div><div><br class=""></div><div><span class="Apple-tab-span" style="white-space:pre">        </span>var isNetworkError: Bool {</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>/// swtich over all values of self goes here.</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>}</div><div><br class=""></div><div><span class="Apple-tab-span" style="white-space:pre">        </span>var isIOError: Bool {</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>/// swtich over all values of self goes here.</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>}</div><div>}</div><div><br class=""></div><div>What the propsal suggests is to simplify this to the following:</div><div><br class=""></div><div><div>enum Error {</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>var isFatal: Bool</div><div><br class=""></div><div><span class="Apple-tab-span" style="white-space: pre;">        </span>case NoError where (isFatal: false, isNetworkError: false, isIOError: false)</div><div><span class="Apple-tab-span" style="white-space: pre;">        </span>case FileNotFound &nbsp;where (isFatal: true, isNetworkError: false, isIOError: true)</div><div><span class="Apple-tab-span" style="white-space: pre;">        </span>...</div><div><br class=""></div><div>}</div><div><br class=""></div><div>So that you assign the additional information to the enum value itself.</div></div><div><br class=""></div><div>Charlie</div><br class=""><blockquote type="cite" class=""><div class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class=""><br class=""></div><br class=""><div class=""><blockquote type="cite" class=""><div class="">On 26 May 2016, at 1:47 PM, David Sweeris via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><meta http-equiv="Content-Type" content="text/html charset=utf-8" class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><br class=""><div class=""><blockquote type="cite" class=""><div class="">On May 25, 2016, at 10:27 PM, Jacob Bandes-Storch &lt;<a href="mailto:jtbandes@gmail.com" class="">jtbandes@gmail.com</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class=""><div class="gmail_extra"><div class="gmail_quote">On Wed, May 25, 2016 at 8:15 PM, David Sweeris via swift-evolution <span dir="ltr" class="">&lt;<a href="mailto:swift-evolution@swift.org" target="_blank" class="">swift-evolution@swift.org</a>&gt;</span> wrote:<br class=""><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><div style="word-wrap:break-word" class=""><span class=""><div class="">On May 25, 2016, at 7:37 AM, Leonardo Pessoa via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" target="_blank" class="">swift-evolution@swift.org</a>&gt; wrote:</div></span><div class=""><span class=""><div class=""><blockquote type="cite" class=""><br class=""><div class=""><div class=""><div class=""><div style="font-family:Calibri,sans-serif;font-size:11pt" class="">Hi,<br class=""><br class="">Couldn't this be solved by using tuples? If not because the syntax is not allowed I think this would be more coherent to do it using current syntax.<br class=""><br class="">enum Planet : (mass: Float, radius: Float) {<br class="">&nbsp;&nbsp;&nbsp; case mercury = (mass: 3.303e+23, radius: 2.4397e6)<br class="">&nbsp;&nbsp;&nbsp; case venus = (mass: 4.869e+24, radius: 6.0518e6)<br class="">&nbsp;&nbsp;&nbsp; case earth = (mass: 5.976e+24, radius: 6.37814e6)<br class="">&nbsp;&nbsp;&nbsp; case mars = (mass: 6.421e+23, radius: 3.3972e6)<br class="">&nbsp;&nbsp;&nbsp; case jupiter = (mass: 1.9e+27, radius: 7.1492e7)<br class="">&nbsp;&nbsp;&nbsp; case saturn = (mass: 5.688e+26, radius: 6.0268e7)<br class="">&nbsp;&nbsp;&nbsp; case uranus = (mass: 8.686e+25, radius: 2.5559e7)<br class="">&nbsp;&nbsp;&nbsp; case neptune = (mass: 1.024e+26, radius: 2.4746e7)<br class="">}</div></div></div></div></blockquote></div><div class=""><br class=""></div></span>This would be my preferred solution… AFAIK, the only reason we can’t do it now is that Swift currently requires RawValue be an integer, floating-point value, or string. I don’t know why the language has this restriction, so I can’t comment on how hard it would be to change.<div class=""><br class=""></div></div><div class="">- Dave Sweeris</div></div></blockquote><div class=""><br class=""></div>Except you'd have to write Planet.mercury.rawValue.mass, rather than Planet.mercury.mass.<div class=""><br class=""></div><div class="">This could be one or two proposals: allow enums with tuple RawValues, and allow `TupleName.caseName.propertyName` to access a tuple element without going through .rawValue.</div></div></div></div></div></blockquote></div><br class=""><div class="">Good point… Has there been a thread on allowing raw-valued enums to be treated as constants of type `RawValue` yet? Either way, removing the restriction on what types can be a RawValue is still my preferred solution.</div><div class=""><br class=""></div><div class="">- Dave Sweeris</div></div>_______________________________________________<br class="">swift-evolution mailing list<br class=""><a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a><br class=""><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" class="">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br class=""></div></blockquote></div><br class=""></div>_______________________________________________<br class="">swift-evolution mailing list<br class=""><a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a><br class="">https://lists.swift.org/mailman/listinfo/swift-evolution<br class=""></div></blockquote></div><br class=""></body></html>