<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="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 (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. 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. 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=""> </span><span style="color: rgb(186, 45, 162);" class=""> </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=""> 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=""> let</span><span style="font-variant-ligatures: no-common-ligatures;" class=""> bookCount: </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=""> = 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: </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=""> let</span><span style="font-variant-ligatures: no-common-ligatures;" class=""> hasBooks: </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=""> = 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: </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=""> </span><span style="color: rgb(186, 45, 162);" class=""> </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=""> let</span><span style="font-variant-ligatures: no-common-ligatures;" class=""> name: </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=""> = 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=""> let</span><span style="font-variant-ligatures: no-common-ligatures;" class=""> bookCount: </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=""> = 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=""> let</span><span style="font-variant-ligatures: no-common-ligatures;" class=""> hasBooks: </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=""> = 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 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></body></html>