<html><head><meta http-equiv="Content-Type" content="text/html charset=us-ascii"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class=""><blockquote type="cite" class=""><div dir="ltr" class=""><div class="gmail_extra">(Tommy, did you see the line in the original proposal suggesting that you'd initialize stored properties as if they were additional named associated values? E.g.: <span class="" style="font-size: 13px;">let expr = .Number(3, location: 5, length: 1). I think if you were to reassign expr -- if it were a var -- you'd need to re-assign location and length, too; they wouldn't transfer.)</span></div></div></blockquote><br class=""></div><div class="">Nope, I missed that (sorry). If at all, this seems a reasonable way to implement it. </div><div class=""><br class=""></div><div class="">By the way it requires there be no duplicate field labels. Also it seems logical to either have a fixed initializer parameter order (first the associated values, then the labeled common ones in order of declaration), <i class="">*or* </i>to allow any order (in case all associated values have labels as well).</div><div class=""><br class=""></div><div class="">My only objection to this proposal is still whether the number of cases where this is useful warrants the added complexity and potential confusion for newcomers. I haven't encountered many situations where these stored common properties would be very useful but ymmv.</div><div class=""><br class=""></div><div class="">/T</div><br class=""><div><blockquote type="cite" class=""><div class="">Op 10 dec. 2015, om 00:06 heeft Alex Lew <<a href="mailto:alexl.mail+swift@gmail.com" class="">alexl.mail+swift@gmail.com</a>> het volgende geschreven:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class=""><div class="gmail_extra">Interesting proposal! In Swift's docs on Pattern Matching (<a href="https://github.com/apple/swift/blob/master/docs/Pattern%20Matching.rst" class="">https://github.com/apple/swift/blob/master/docs/Pattern%20Matching.rst</a>), the inability to easily access a value that is relevant to <i class="">all </i>cases of an enum is explicitly mentioned as a minus of Swift's approach:</div><ul style="padding:0px 0px 0px 2em;margin-top:0px;margin-bottom:0px;color:rgb(51,51,51);font-family:'Helvetica Neue',Helvetica,'Segoe UI',Arial,freesans,sans-serif,'Apple Color Emoji','Segoe UI Emoji','Segoe UI Symbol';font-size:16px" class=""><li style="" class="">minus: needs boilerplate to project out a common member across multiple/all alternatives</li></ul><div class="gmail_extra">The docs even mention that it might be worth providing "special dispensations for ... projecting out common members."</div><div class="gmail_extra"><br class=""></div><div class="gmail_extra">This seems like an elegant solution to the all-alternatives problem (though not the multiple-alternatives problem). +1</div><div class="gmail_extra"><br class=""></div><div class="gmail_extra">It is worth considering Frederick's point above that this essentially makes struct X { ... } the same as enum X { case OnlyCase; ... }. Also, you'd probably want to make sure that none of the associated values shared a name with a stored property, to avoid confusion when initializing (constructing?) new enums.</div><div class="gmail_extra"><br class=""></div><div class="gmail_extra">(Tommy, did you see the line in the original proposal suggesting that you'd initialize stored properties as if they were additional named associated values? E.g.: <span style="font-size:13px" class="">let expr = .Number(3, location: 5, length: 1). I think if you were to reassign expr -- if it were a var -- you'd need to re-assign location and length, too; they wouldn't transfer.)</span></div><div class="gmail_extra"><br class=""></div><div class="gmail_extra">-Alex</div><div class="gmail_extra"><br class=""><div class="gmail_quote">On Wed, Dec 9, 2015 at 4:44 PM, Tommy van der Vorst via swift-evolution <span dir="ltr" class=""><<a href="mailto:swift-evolution@swift.org" target="_blank" class="">swift-evolution@swift.org</a>></span> wrote:<br class=""><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><span class="">> None of the state-like nature of enums would be lost.<br class="">
><br class="">
> enum Something {<br class="">
> case StateA<br class="">
> case StateB(Double)<br class="">
> var prop: Int<br class="">
> }<br class="">
><br class="">
> Would simply be a another way to write:<br class="">
><br class="">
> enum Something {<br class="">
> case StateA(Int)<br class="">
> case StateB(Double, Int)<br class="">
> }<br class="">
<br class="">
<br class="">
</span>Sure, but do we really need special syntax then? To me the above way of writing is much clearer on which data is available at what point than the variant with the separate 'var' declaration. You can even label the different values in the associated data tuple.<br class="">
<br class="">
Putting data shared across states in a separate 'var' declaration introduces some other issues as well: when an enum is reassigned (i.e. self = .StateB(...)), is the variable emptied somehow, or is it kept? How would you even initialize the value of a non-optional stored property that is not part of the case associated tuple (as the variables are not a 'requirement' of the case tuple, perhaps only optionals should be allowed)?<br class="">
<br class="">
/T<br class="">
<div class=""><div class="h5"><br class="">
_______________________________________________<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" rel="noreferrer" target="_blank" class="">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br class="">
</div></div></blockquote></div><br class=""></div></div>
</div></blockquote></div><br class=""></body></html>