<html xmlns="http://www.w3.org/1999/xhtml"><head>
<style type="text/css">body{font-family:Helvetica,Arial;font-size:13px}</style>
<title></title>
</head>
<body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;">
<div id="bloop_customfont" style="font-family:Helvetica,Arial;font-size:13px; color: rgba(0,0,0,1.0); margin: 0px; line-height: auto;">
<div>
<blockquote type="cite" class="clean_bq" style="font-family: Helvetica, Arial; font-size: 13px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;">
<div style="font-family: 'helvetica Neue', helvetica;">I don't think the struct functionality makes much sense. There are two ways you can use the struct<...> construct:
</div>
</blockquote>
</div>
<p>So does `enum<>` makes not much sense, I guess? I can’t think of any use-case were `enum<>` could do something what `struct<>` can’t.
</p>
<div>
<div>
<blockquote type="cite" class="clean_bq" style="font-family: Helvetica, Arial; font-size: 13px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;">
<div style="font-family: 'helvetica Neue', helvetica;">1. struct<SomeConcreteStruct, Protocol1, Protocol2>. In this case the struct<...> representation is unnecessary; the protocols that are available to the user are known at compile-time, and structs can't have subtypes that conform to additional protocols like classes can. There is an example marked "func boo(value: struct<SomeStruct>) /* equivalent to */ func boo(value: SomeStruct)"; my question is why having more than two ways to express the same idea makes the language better, easier to use, etc.
</div>
</blockquote>
</div>
<p>Was this clarified somewhere, I mean that value types won’t have subtypes ever? This would be nice to know.</p>
<p>We already can write the same (ugly) scenario with protocols:<br>
protocol A {}<br>
extension A {<br>
func foo() {<br>
print("foooo")<br>
}<br>
}<br>
<br>
// this is the refined design that we all use<br>
func boo(value: A) {<br>
value.foo()<br>
}<br>
<br>
// this might be the original design <br>
func zoo(value: protocol<A>) {<br>
boo(value)<br>
}<br>
<br>
struct B: A {}<br>
let value = B()<br><br>
zoo(value)<br>
boo(value)<br>
</p><p>The main idea behind `struct<>` etc. is not to make the language complicated, but to add <u>symmetry to the type system</u>, which should already have been there from the beginning. Compared to the little example I just wrote, we all already use the refined format of the (not present) base `struct<>`.</p><p>So if value types might have subtypes one day, this wouldn’t be hard to upgrade I suppose. Anyways I’ll move that part of the proposal to the future direction.</p>
<div>
<div>
<div><blockquote type="cite" class="clean_bq" style="font-family: Helvetica, Arial; font-size: 13px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><div style="font-family: 'helvetica Neue', helvetica;">2. struct<T, Protocol1, Protocol2>. In this case struct<...> is being used as an add-on to the generics system to denote a 'must be value type' constraint. However, I think a 'T : class'-like 'struct' constraint makes more sense, both because it fits better with the existing 'class' constraint and because it can be used anywhere the generic system allows a type parameter to be constrained. A generic 'struct' constraint would give the currently generics system as much expressive power as struct<...>.</div></blockquote></div><p>True, but I feel like there is a change incoming in that direction (<a href="https://lists.swift.org/pipermail/swift-evolution/Week-of-Mon-20160502/016286.html"><span style="color: rgb(0, 0, 0);">[swift-evolution] Should we rename "class" when referring to protocol conformance?</span></a>) and I don’t think the core team will decide to introduce `T: class`-like `struct` or `enum` constraint. :/</p><p>struct C<T: struct where T: SomeProtocol> {</p><p> var value: T?</p><p> func set(value: T) {</p><p> self.value = value</p><p> }</p><p>}</p><p>This would be nice to have. And yes this does look way better than:</p><p>struct C<struct<T, SomeProtocol>> {</p><p> […]</p><p>}</p><p>But isn’t this again a refined usage of the base format (`struct<>` in this case)!? </p><p>One other example that comes to mind, where I can’t really tell if this would be possible to express with `struct<>`, can be defined outside of the generic scope just like `class<SomeBaseClass, SomeProtocol>` or `all<SomeBaseClass, SomeProtocol>`:</p><p>var structArray: [struct<Any, SomeProtocol>]</p><p>Would this work? This is an interesting case, where no values inside the struct can be reference-types!</p></div><p>
</p>
<div>
<div><blockquote type="cite" class="clean_bq" style="font-family: Helvetica, Arial; font-size: 13px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><div style="font-family: 'helvetica Neue', helvetica;">Overall, rather than having this be a separate feature I think it should be developed as part of the "Generalized Existentials" feature that is already on the roadmap for Swift 3. The cases where adding class<...>, struct<...>, etc can improve expressive power are covered by allowing variables to take existential types with constraints. The one big feature that Generalized Existentials should absorb from this proposal is allowing the representation of a concrete class type with protocol constraints (<MyClass, SomeProtocol, AnotherProtocol>).</div></blockquote></div><p>Is there any reading you can point me to, so I can include or quote it into the proposal?</p></div></div></div></div>
<div id="bloop_sign_1463209857876615936" class="bloop_sign">
<div style="font-family:helvetica,arial;font-size:13px">-- <br>
Adrian Zubarev<br>
Sent with Airmail
</div>
</div>
<br>
<p class="airmail_on">Am 14. Mai 2016 bei 06:06:12, Austin Zheng (<a href="mailto:austinzheng@gmail.com">austinzheng@gmail.com</a>
) schrieb:
</p>
<blockquote type="cite" class="clean_bq">
<div style="color: rgb(0, 0, 0); font-family: 'helvetica Neue', helvetica; font-size: 13px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;">
<span>
<br>
</span>
</div>
</blockquote>
</body></html>