<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head><body dir="auto"><div>This can be <i>made</i> typesafe if the ObjectIdentifier of the archetype is stored with the key and checked on retrieval.<br><br>~Robert Widmann</div><div><br>2017/01/23 11:43、Thorsten Seitz via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>&gt; のメッセージ:<br><br></div><blockquote type="cite"><div><meta http-equiv="content-type" content="text/html; charset=utf-8"><div></div><div><br></div><div><br>Am 14.01.2017 um 14:50 schrieb Gwendal Roué via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>&gt;:<br><br></div><blockquote type="cite"><div><meta http-equiv="Content-Type" content="text/html charset=utf-8"><div><blockquote type="cite" class=""><div class=""><div style="font-family: Helvetica; font-size: 12px; 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;" class=""><blockquote type="cite" class=""><div class=""><div class="" style="font-family: Helvetica; font-size: 12px; 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;"><blockquote type="cite" class=""><div class=""><div class="" style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><div class="">Where generic subscripts are concerned, there are a couple of different things to express:</div><div class="">- Generic parameter &nbsp;(I can understand various co-ordinates for the data)</div><div class="">- Generic return type (I can construct your preferred representation of the data)</div><div class="">- Generic setter type (I can set the data using various compatible types):</div></div></div></blockquote><div class=""><br class=""></div>I think all of these should be expressed with a single generic signature on the subscript itself. The element type passed to the setter and returned from the getter should be the same IMO, otherwise it’s not clear how it will work.</div></div></blockquote><div class=""><br class=""></div>Yes. &nbsp;It's quite important that any particular subscript reference is still a single consistent entity, even if generic; we would not want, say, a read-modify-write access to be able to somehow invoke the getter and setter at different generic arguments, or to traffic in different element types.</div><div style="font-family: Helvetica; font-size: 12px; 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;" class=""><br class=""></div><div style="font-family: Helvetica; font-size: 12px; 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;" class="">I'm also not sure we'd ever want the element type to be inferred from context like this. &nbsp;Generic subscripts as I see it are about being generic over *indexes*, not somehow about presenting a polymorphic value.</div></div></blockquote><div><br class=""></div></div>This is a consequence of your vision of subscript. If interesting, it is also limiting for no real purpose.<div class=""><br class=""></div><div class="">As the developer of a Swift database library, I'd like to offer a better API than the following:<div class=""><br class=""></div><div class=""><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(0, 132, 0);" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""><span style="color: rgb(186, 45, 162);" class="">&nbsp; &nbsp;</span><span style="color: rgb(186, 45, 162);" class="">&nbsp;</span>// Current state of affairs</span></div></div><div class=""><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #ba2da2" class="">&nbsp; &nbsp; let</span><span style="font-variant-ligatures: no-common-ligatures" class=""> name: </span><span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">String</span><span style="font-variant-ligatures: no-common-ligatures" class=""> = row.</span><span style="font-variant-ligatures: no-common-ligatures; color: #31595d" class="">value</span><span style="font-variant-ligatures: no-common-ligatures" class="">(named: </span><span style="font-variant-ligatures: no-common-ligatures; color: #d12f1b" class="">"name"</span><span style="font-variant-ligatures: no-common-ligatures" class="">)</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: rgb(186, 45, 162);" class="">&nbsp; &nbsp; let</span><span style="font-variant-ligatures: no-common-ligatures;" class="">&nbsp;bookCount:&nbsp;</span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(112, 61, 170);" class="">Int</span><span style="font-variant-ligatures: no-common-ligatures;" class="">&nbsp;= row.</span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(49, 89, 93);" class="">value</span><span style="font-variant-ligatures: no-common-ligatures;" class="">(named:&nbsp;</span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(209, 47, 27);" class="">"bookCount"</span><span style="font-variant-ligatures: no-common-ligatures;" class="">)</span></div></div><div class=""><span style="font-variant-ligatures: no-common-ligatures" class=""><div class=""><span style="font-variant-ligatures: no-common-ligatures;" class=""><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: rgb(186, 45, 162);" class="">&nbsp; &nbsp; let</span><span style="font-variant-ligatures: no-common-ligatures;" class="">&nbsp;hasBooks:&nbsp;</span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(112, 61, 170);" class="">Bool</span><span style="font-variant-ligatures: no-common-ligatures;" class="">&nbsp;= row.</span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(49, 89, 93);" class="">value</span><span style="font-variant-ligatures: no-common-ligatures;" class="">(named:&nbsp;</span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(209, 47, 27);" class="">"bookCount"</span><span style="font-variant-ligatures: no-common-ligatures;" class="">)</span></div><div class=""><span style="font-variant-ligatures: no-common-ligatures;" class=""><br class=""></span></div></span></div></span></div><div class="">Instead, I wish I could offer GRDB.swift would let its users write:</div></div><div class=""><br class=""></div><div class=""><div class=""><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(0, 132, 0);" class=""><span style="font-variant-ligatures: no-common-ligatures;" class=""><span style="color: rgb(186, 45, 162);" class="">&nbsp; &nbsp;</span><span style="color: rgb(186, 45, 162);" class="">&nbsp;</span>// With improved subscripts</span></div></div><div class=""><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><div class=""><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: rgb(186, 45, 162);" class="">&nbsp; &nbsp; let</span><span style="font-variant-ligatures: no-common-ligatures;" class="">&nbsp;name:&nbsp;</span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(112, 61, 170);" class="">String</span><span style="font-variant-ligatures: no-common-ligatures;" class="">&nbsp;= row</span><span style="font-variant-ligatures: no-common-ligatures;" class="">[</span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(209, 47, 27);" class="">"name"</span>]</div><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: rgb(186, 45, 162);" class="">&nbsp; &nbsp; let</span><span style="font-variant-ligatures: no-common-ligatures;" class="">&nbsp;bookCount:&nbsp;</span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(112, 61, 170);" class="">Int</span><span style="font-variant-ligatures: no-common-ligatures;" class="">&nbsp;= row</span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(209, 47, 27);" class=""><span style="color: rgb(0, 0, 0);" class="">[</span>"bookCount"</span><span style="font-variant-ligatures: no-common-ligatures;" class="">]</span></div></div><div class=""><span style="font-variant-ligatures: no-common-ligatures;" class=""><div class=""><span style="font-variant-ligatures: no-common-ligatures;" class=""><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: rgb(186, 45, 162);" class="">&nbsp; &nbsp; let</span><span style="font-variant-ligatures: no-common-ligatures;" class="">&nbsp;hasBooks:&nbsp;</span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(112, 61, 170);" class="">Bool</span><span style="font-variant-ligatures: no-common-ligatures;" class="">&nbsp;= row</span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(209, 47, 27);" class=""><span style="color: rgb(0, 0, 0);" class="">[</span>"bookCount"</span><span style="font-variant-ligatures: no-common-ligatures;" class="">]</span></div><div class=""><br class=""></div><div class=""><div style="font-family: Helvetica; font-size: 12px;" class="">And this requires genericity on return type.</div></div></span></div></span></div></div></div></div></div></blockquote><div><br></div>This is not typesafe at all if the type does not depend on the argument. I'd prefer keys carrying the meta information of their respective database column keeping the whole API typesafe.<div><br></div><div>-Thorsten</div><div>&nbsp;<br><blockquote type="cite"><div><div class=""><div class=""><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><div class=""><span style="font-variant-ligatures: no-common-ligatures;" class=""><div class=""><span style="font-variant-ligatures: no-common-ligatures;" class=""><div class=""><div style="font-family: Helvetica; font-size: 12px;" class=""><br class=""></div><div style="font-family: Helvetica; font-size: 12px;" class="">Gwendal</div><div style="font-family: Helvetica; font-size: 12px;" class=""><br class=""></div><div style="font-family: Helvetica; font-size: 12px;" class=""><div class=""></div></div></div></span></div></span></div></div></div></div></div></blockquote><blockquote type="cite"><div><span>_______________________________________________</span><br><span>swift-evolution mailing list</span><br><span><a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a></span><br><span><a href="https://lists.swift.org/mailman/listinfo/swift-evolution">https://lists.swift.org/mailman/listinfo/swift-evolution</a></span><br></div></blockquote></div></div></blockquote><blockquote type="cite"><div><span>_______________________________________________</span><br><span>swift-evolution mailing list</span><br><span><a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a></span><br><span><a href="https://lists.swift.org/mailman/listinfo/swift-evolution">https://lists.swift.org/mailman/listinfo/swift-evolution</a></span><br></div></blockquote></body></html>