<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head><body><div><div style="font-family: Calibri,sans-serif; font-size: 11pt;">I think I should start writing that proposal for enum case names now.<br><br>L</div></div><div dir="ltr"><hr><span style="font-family: Calibri,sans-serif; font-size: 11pt; font-weight: bold;">From: </span><span style="font-family: Calibri,sans-serif; font-size: 11pt;"><a href="mailto:swift-evolution@swift.org">Vladimir.S via swift-evolution</a></span><br><span style="font-family: Calibri,sans-serif; font-size: 11pt; font-weight: bold;">Sent: </span><span style="font-family: Calibri,sans-serif; font-size: 11pt;">‎01/‎06/‎2016 07:02 PM</span><br><span style="font-family: Calibri,sans-serif; font-size: 11pt; font-weight: bold;">To: </span><span style="font-family: Calibri,sans-serif; font-size: 11pt;"><a href="mailto:allevato@google.com">Tony Allevato</a></span><br><span style="font-family: Calibri,sans-serif; font-size: 11pt; font-weight: bold;">Cc: </span><span style="font-family: Calibri,sans-serif; font-size: 11pt;"><a href="mailto:swift-evolution@swift.org">swift-evolution</a></span><br><span style="font-family: Calibri,sans-serif; font-size: 11pt; font-weight: bold;">Subject: </span><span style="font-family: Calibri,sans-serif; font-size: 11pt;">Re: [swift-evolution] Ad hoc enums / options</span><br><br></div> &gt; in other words, we could consider allowing this:<br> &gt;&nbsp;&nbsp;&nbsp; func foo(bar: (.fit | .fill)) {<br> &gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; baz(bar: bar)<br> &gt;&nbsp;&nbsp;&nbsp; }<br> &gt;&nbsp;&nbsp;&nbsp; func baz(bar: (.fit | .fill | .florp) { ... }<br> &gt;<br> &gt; In other words, an ad hoc enum T can be used wherever an ad hoc enum U is<br> &gt; expected if T ⊆ U.<br><br>Can't agree with this. Just because the same analogue with tuples : <br>differently defined tuples are different types. Tuples with different order <br>of types in declaration - are different types. So I expect here instance of <br>(.fit | .fill) `bar` is not of the same type as (.fit | .fill | .florp)<br><br>But +1 to be able to 'convert' instance of (.fit | .fill) to instance of <br>(.fit | .fill | .florp). For example(if we'll have init(caseName) and <br>.caseName for enums):<br><br>func foo(bar: (.fit | .fill)) {<br>&nbsp;&nbsp;&nbsp;&nbsp; let bazbar = (.fit | .fill | .florp).init(caseName: bar.caseName)<br>&nbsp;&nbsp;&nbsp;&nbsp; baz(bar: bazbar)<br>}<br>func baz(bar: (.fit | .fill | .florp) { ... }<br><br><br><br>On 02.06.2016 0:38, Tony Allevato wrote:<br>&gt; I find myself agreeing with the idea that ad hoc enums are to enums as<br>&gt; structs are to tuples. Based on that analogy, why should an ad hoc enum<br>&gt; *need* a name (autogenerated or otherwise) any more than a tuple needs a<br>&gt; name? Would those who dislike ad hoc enums argue that this also shouldn't<br>&gt; be allowed:<br>&gt;<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; func foo(bar: (x: Int, y: Int)) {}<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; let t: (x: Int, y: Int) = (x: 5, y: 5)<br>&gt;<br>&gt; If someone writes `(.fit | .fill)` (or whatever the hypothetical syntax<br>&gt; might be), that should just *be* the type the same way that `(x: Int, y:<br>&gt; Int)` is a type without a name, and that type can be used in argument<br>&gt; lists, variables, or whatever. There shouldn't be any worry about<br>&gt; declarations across multiple functions colliding or being incompatible any<br>&gt; more than we would worry about two functions declaring arguments of type<br>&gt; `(x: Int, y: Int)` would collide or be incompatible.<br>&gt;<br>&gt; One side of ad hoc enums that I'd like to see explored is that, by being<br>&gt; unnamed, they're basically anonymous finite sets and we could apply<br>&gt; well-defined subset relationships to them: in other words, we could<br>&gt; consider allowing this:<br>&gt;<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; func foo(bar: (.fit | .fill)) {<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; baz(bar: bar)<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; }<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; func baz(bar: (.fit | .fill | .florp) { ... }<br>&gt;<br>&gt; In other words, an ad hoc enum T can be used wherever an ad hoc enum U is<br>&gt; expected if T ⊆ U.<br>&gt;<br>&gt;<br>&gt; On Wed, Jun 1, 2016 at 1:43 PM L. Mihalkovic via swift-evolution<br>&gt; &lt;swift-evolution@swift.org &lt;mailto:swift-evolution@swift.org&gt;&gt; wrote:<br>&gt;<br>&gt;<br>&gt;<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt; On Jun 1, 2016, at 6:51 PM, Vladimir.S &lt;svabox@gmail.com<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &lt;mailto:svabox@gmail.com&gt;&gt; wrote:<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt;<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt; Yes, I also can support the idea of autogenerated type name (like<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; Enum_fit_OR_fill) as long as it allows to do all the things we are<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; discussing here: declare (.fit|.fill) in function, use .fit on calling<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; side, use (.fit|.fill) to declare temporary variable of type compatible<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; with such function parameter etc.<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt;<br>&gt;<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; It all works because the compiler is just being a thoughless scribe<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; that just writes the standard enum we don't bother to write ourselves.<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; Because the heuristic is simple and straightforward then it is<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; predictible. The enum can be used with its long name be ause it is a<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; real enum. And writing the short form of it also works because the<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; compiler knowns uniquely what the long name is everytime it runs into<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; the short name.<br>&gt;<br>&gt;<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt; But how do you suggest to define a type of such function in<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; `typealias` for example? i.e. for func my(option: (.fit|.fill) {..}<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt;<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt; typealias MyFunc = ((.fit|.fill)) -&gt; ()<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt; or as<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt;<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt; typealias MyFunc = (Enum_fit_OR_fill) -&gt; ()<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt;<br>&gt;<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; Ideally there is no difference whatsoever, there is a single enum, it<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; is produced at the module level, and it has the long form name.<br>&gt;<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; There can be rules that would prevent us from doing that with<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; externally visible APIs, if the core team fuges that we should take the<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; time to write our enums manually and cleanly to make them visible to<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; the world, but it is not a necessary rule.<br>&gt;<br>&gt;<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt;<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt; But I still can't support the idea of limiting the usage of such<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; enums - i.e. "To deal with milti site definition, the compiler would<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; simply flag a error/warning, or be silent in the presence of a new<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; annotation:". I really think we need then introduce the same rule for<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; tuples - so no one can use the same tuple declaration in function -<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; they then should declare separate struct type or use @something for<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; such functions. Nobody wants such rule for tuples.<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt;<br>&gt;<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; Multi site thing is not a limitation... Is is a proposed rule to say<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; that we are able to be lazy twice without being penalized. Yhe compiler<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; does not like when we define the same thing twice, and thse short form<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; amount to doing what he does not let us do. But because this is about<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; concise and lazy, then the compiler can let us get away with it if we<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; use an annotation that lets it know that "it is not a mistake.. I<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; really dont want to write that enum myself, even though I am using the<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; same abbreviation twice". Otherwise, the compiler would let us know<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; that the second time could be a mistake because there is already<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; something with the same name...<br>&gt;<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; But again this is a separate idea from the core notion of a syntax<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; sugaring for writing real enums the lazy (clever) way<br>&gt;<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt;&gt; On 01.06.2016 19:04, L. Mihalkovic wrote:<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt;&gt; The only problem with this proposal is to consider them ad-hoc<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; enums... If we view them as having nothing ad-hoc about them and the<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; thing to be a simple sugaring exercise, then I think all the opositions<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; on grounds of breaking the language disapear. It still does not mean it<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; should be done if the core team does not like the idea of encouraging<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; laziness, or simply do not like what it makes them look like. No matter<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; what, this type of sugaring exercise has been clearly stated as out of<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; scope for 3.0<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt;&gt;<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt;&gt;&gt;&gt; On Jun 1, 2016, at 2:38 PM, Vladimir.S via swift-evolution<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &lt;swift-evolution@swift.org &lt;mailto:swift-evolution@swift.org&gt;&gt; wrote:<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt;&gt;&gt;&gt;<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt;&gt;&gt;&gt; On 01.06.2016 11:00, Austin Zheng wrote:<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt;&gt;&gt;&gt; Tuples are a structural type, they are described entirely by the fact<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt;&gt;&gt;&gt; that they are a tuple, plus their contained types.<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt;&gt;&gt;&gt;<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt;&gt;&gt;&gt; Enum cases are not individual types; that precedent exists nowhere in<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt;&gt;&gt;&gt; Swift. You can't (yet) build a structural type out of something that<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt;&gt;&gt;&gt; isn't a type. The fact that you had to propose something like<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt;&gt;&gt;&gt; "AdhocEnumFitFill_2383748" as an autogenerated name for the type<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt;&gt;&gt;&gt; demonstrates the proposal's weaknesses: a tuple is an ad-hoc type that<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt;&gt;&gt;&gt; describes itself, while an anonymous enum isn't.<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt;&gt;&gt;<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt;&gt;&gt; Yes, I understand the point about the type of such adhoc enum.<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt;&gt;&gt; The only workaround I can see in this case(if we'd really want to<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; have it in language) if adhoc enum type will be `(.Fit|.Fill)` i.e.<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; textual representation if the declared type. As I understand this also<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; could not be a solution.. I.e. for example<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; `(Int,String,(.Fit|.Fill))-&gt;String`<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt;&gt;&gt;<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt;&gt;&gt; From other point of view, adding such type to typesystem will add<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; some consistence : you can create a function that don't need definition<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; of separate structure type(tuple will be used) and don't need separate<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; enum type(ad-hoc enum will be used). I.e. all data the function needs<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; to process could be described in function definition. Today we need to<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; use ugly Bool flags in case we want to achieve the same target.<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt;&gt;&gt;<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt;&gt;&gt;&gt;<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt;&gt;&gt;&gt; Now if enum cases were equivalent if they had the same name (like how<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt;&gt;&gt;&gt; "Int" means the same thing no matter what tuple or generic type it is<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt;&gt;&gt;&gt; used in), we'd have a good foundation for a self-describing structural<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt;&gt;&gt;&gt; type. But this isn't how the existing named enum types work. Why would<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt;&gt;&gt;&gt; it be a good idea to make anonymous enum cases interchangeable by<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; name?<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt;&gt;&gt;&gt; Properties on different types aren't interchangeable, even if they<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; have<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt;&gt;&gt;&gt; the same type. In fact, no type member that I am aware of is<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt;&gt;&gt;&gt; interchangeable solely on the basis of name. An<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; "ArtistAction.Draw" and<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt;&gt;&gt;&gt; "CowboyAction.Draw" might have the same name, but they mean completely<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt;&gt;&gt;&gt; different things.<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt;&gt;&gt;<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt;&gt;&gt; I don't think they should be 'interchangeable by name', but just<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; like tuples if you defined adhoc enum with exactly the same cases as<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; ad-hoc enum in function parameters - then they are of the same type.<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt;&gt;&gt;<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt;&gt;&gt; I.e. :<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt;&gt;&gt;<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt;&gt;&gt; func foo(option: (.fit|.fill)) {..}<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt;&gt;&gt;<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt;&gt;&gt; foo(.fit) // .fit is of type&nbsp; (.fit|.fill) from definition<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt;&gt;&gt;<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt;&gt;&gt; let e : (.fit|.fill) = .fit<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt;&gt;&gt; foo(e) // e is of (.fit|.fill) type, equal to definition<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt;&gt;&gt;<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt;&gt;&gt; but<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt;&gt;&gt;<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt;&gt;&gt; func foo2(option: (.fit|.fill|.other)) {..}<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt;&gt;&gt;<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt;&gt;&gt; foo2(.fit) // ok, here .fit is of (.fit|.fill|.other) type<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt;&gt;&gt; foo2(e) --&gt; Error, e is not of type (.fit|.fill|.other)<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt;&gt;&gt;<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt;&gt;&gt;&gt;<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt;&gt;&gt;&gt; Finally, I have to ask: if you are updating your anonymous enum in<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt;&gt;&gt;&gt; multiple places, how much effort have you actually saved over a<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; one-line<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt;&gt;&gt;&gt; enum definition? In fact, tuples are a great example of this: best<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt;&gt;&gt;&gt; practices usually state that they are good for ad-hoc destructuring,<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt;&gt;&gt;&gt; such as retrieving multiple return values from a function or pattern<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt;&gt;&gt;&gt; matching across several values at once, but structs are better<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; used for<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt;&gt;&gt;&gt; almost everything else, since they carry semantic meaning that tuples<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt;&gt;&gt;&gt; don't.<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt;&gt;&gt;&gt;<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt;&gt;&gt;<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt;&gt;&gt; Just the same pros and cons for ad-hoc enums vs enum declaration as<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; for tuples vs struct declaration. Yes can use it with care and you can<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; use it in wrong way.<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt;&gt;&gt;<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt;&gt;&gt; Btw, I feel like this could be very handy to return adhoc enum:<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt;&gt;&gt;<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt;&gt;&gt; func something() -&gt; (.one|.two|.three) {...}<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt;&gt;&gt;<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt;&gt;&gt;&gt; I hope that clarifies my thoughts on the matter.<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt;&gt;&gt;&gt;<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt;&gt;&gt;&gt; Best, Austin<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt;&gt;&gt;&gt;<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt;&gt;&gt;&gt;<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt;&gt;&gt;&gt;&gt; On Jun 1, 2016, at 12:36 AM, Vladimir.S &lt;svabox@gmail.com<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &lt;mailto:svabox@gmail.com&gt;&gt; wrote:<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt;&gt;&gt;&gt;&gt;<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt;&gt;&gt;&gt;&gt; On 01.06.2016 9:55, Austin Zheng via swift-evolution wrote:<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt;&gt;&gt;&gt;&gt;&gt; Maybe it's overkill. My personal opinion is that breaking the<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt;&gt;&gt;&gt;&gt;&gt; symmetry of the language like this (are there any other types of<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt;&gt;&gt;&gt;&gt;&gt; function arguments that cannot be passed as either variable values<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt;&gt;&gt;&gt;&gt;&gt; or literals?) is too much a price to pay. Your library thinks it's<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt;&gt;&gt;&gt;&gt;&gt; being clever and vends its functions as taking anonymous enum flags,<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt;&gt;&gt;&gt;&gt;&gt; and now there are a bunch of things I can't do with those functions<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt;&gt;&gt;&gt;&gt;&gt; anymore.<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt;&gt;&gt;&gt;&gt;&gt;<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt;&gt;&gt;&gt;&gt;&gt; A regular enum can be declared in one line anyways:<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt;&gt;&gt;&gt;&gt;&gt;<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt;&gt;&gt;&gt;&gt;&gt; enum ScaleCropMode { case Fit, Fill }<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt;&gt;&gt;&gt;&gt;<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt;&gt;&gt;&gt;&gt; Why do we have tuples? Struct could be defined by one line `struct<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt;&gt;&gt;&gt;&gt; SomeValue { var x = 0, y = 0 }` ;-) I.e. from my point of view<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt;&gt;&gt;&gt;&gt; developer should decide what he/she wants to use: ad-hoc enum or<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt;&gt;&gt;&gt;&gt; defined enum type *exactly* as now he/she can decide to use the same<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt;&gt;&gt;&gt;&gt; tuples in multiply functions instead of one defined struct type.<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt;&gt;&gt;&gt;&gt;<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt;&gt;&gt;&gt;&gt; I replied regarding the variable on other message. (In short: I think<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt;&gt;&gt;&gt;&gt; of the same principle as for tuples: you can declare variable `let e:<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt;&gt;&gt;&gt;&gt; (.fill | .fit) = .fill` and use it)<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt;&gt;&gt;&gt;&gt;<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt;&gt;&gt;&gt;&gt;&gt;<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt;&gt;&gt;&gt;&gt;&gt; Austin<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt;&gt;&gt;&gt;&gt;&gt;<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt;&gt;&gt;&gt;&gt;&gt;&gt; On May 31, 2016, at 11:44 PM, Charles Constant<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt;&gt;&gt;&gt;&gt;&gt;&gt; &lt;charles@charlesism.com &lt;mailto:charles@charlesism.com&gt;<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &lt;mailto:charles@charlesism.com &lt;mailto:charles@charlesism.com&gt;&gt;&gt; wrote:<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt;&gt;&gt;&gt;&gt;&gt;&gt;<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; It breaks the ability to pass in a variable containing the<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; desired<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt;&gt;&gt;&gt;&gt;&gt;&gt; value, rather than the literal value itself.<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt;&gt;&gt;&gt;&gt;&gt;&gt;<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt;&gt;&gt;&gt;&gt;&gt;&gt; Maybe that's appropriate? If the caller is not passing in a<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt;&gt;&gt;&gt;&gt;&gt;&gt; hardcoded enum case, then that enum is probably general enough<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt;&gt;&gt;&gt;&gt;&gt;&gt; that it warrants a normal enum. But there are also situations<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt;&gt;&gt;&gt;&gt;&gt;&gt; where the same function is called from several files in the same<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt;&gt;&gt;&gt;&gt;&gt;&gt; code-base with different flags. Those are situations where it<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt;&gt;&gt;&gt;&gt;&gt;&gt; feels like overkill to clutter up my codebase with separate enums,<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt;&gt;&gt;&gt;&gt;&gt;&gt; only used by a single function.<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt;&gt;&gt;&gt;&gt;&gt;&gt;<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt;&gt;&gt;&gt;&gt;&gt;&gt;<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt;&gt;&gt;&gt;&gt;&gt;&gt;<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt;&gt;&gt;&gt;&gt;&gt;&gt;<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt;&gt;&gt;&gt;&gt;&gt;&gt;<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt;&gt;&gt;&gt;&gt;&gt;&gt; On Tue, May 31, 2016 at 9:24 PM, Austin Zheng via swift-evolution<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt;&gt;&gt;&gt;&gt;&gt;&gt; &lt;swift-evolution@swift.org &lt;mailto:swift-evolution@swift.org&gt;<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &lt;mailto:swift-evolution@swift.org &lt;mailto:swift-evolution@swift.org&gt;&gt;&gt;<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt;&gt;&gt;&gt;&gt;&gt;&gt; wrote:<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt;&gt;&gt;&gt;&gt;&gt;&gt;<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt;&gt;&gt;&gt;&gt;&gt;&gt; I admire the desire of this proposal to increase the readability<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt;&gt;&gt;&gt;&gt;&gt;&gt; of code. I'm -1 to the proposal itself, though:<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt;&gt;&gt;&gt;&gt;&gt;&gt;<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt;&gt;&gt;&gt;&gt;&gt;&gt; - It breaks the ability to pass in a variable containing the<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt;&gt;&gt;&gt;&gt;&gt;&gt; desired value, rather than the literal value itself. (Unless you<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt;&gt;&gt;&gt;&gt;&gt;&gt; actually want a not-so-anonymous enum type whose definition<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt;&gt;&gt;&gt;&gt;&gt;&gt; happens to live in a function signature rather than somewhere<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt;&gt;&gt;&gt;&gt;&gt;&gt; you'd usually expect a type definition to live.) - It breaks the<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt;&gt;&gt;&gt;&gt;&gt;&gt; ability to store a reference to the function in a variable of<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt;&gt;&gt;&gt;&gt;&gt;&gt; function type (ditto). - Almost every time I've wanted to use one<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt;&gt;&gt;&gt;&gt;&gt;&gt; of these "anonymous enums" in my code, I've ended up needing to<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt;&gt;&gt;&gt;&gt;&gt;&gt; use that same enum elsewhere. In my experience, 'lightweight<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt;&gt;&gt;&gt;&gt;&gt;&gt; enums' don't end up saving much time compared to a full-fledged<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt;&gt;&gt;&gt;&gt;&gt;&gt; one.<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt;&gt;&gt;&gt;&gt;&gt;&gt;<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt;&gt;&gt;&gt;&gt;&gt;&gt; Like Brent said, I have to say no to any proposal that tries to<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt;&gt;&gt;&gt;&gt;&gt;&gt; make enums synonyms for numerical values. What happens if you<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt;&gt;&gt;&gt;&gt;&gt;&gt; rearrange your anonymous enum cases between library versions? Do<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt;&gt;&gt;&gt;&gt;&gt;&gt; you somehow store an opaque case-to-UInt8 table somewhere for<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt;&gt;&gt;&gt;&gt;&gt;&gt; every anonymous enum you define for resilience? What happens when<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt;&gt;&gt;&gt;&gt;&gt;&gt; people start bringing back terrible C patterns, like doing<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt;&gt;&gt;&gt;&gt;&gt;&gt; arithmetic or bitwise ops on the underlying case values? At least<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt;&gt;&gt;&gt;&gt;&gt;&gt; you have to try pretty hard as it is to abuse Swift's enums.<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt;&gt;&gt;&gt;&gt;&gt;&gt;<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt;&gt;&gt;&gt;&gt;&gt;&gt; Austin<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt;&gt;&gt;&gt;&gt;&gt;&gt;<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt;&gt;&gt;&gt;&gt;&gt;&gt; On Tue, May 31, 2016 at 8:25 PM, Brent Royal-Gordon via<br>&gt;&nbsp; <br><div>[The entire original message is not included.]</div></body></html>