<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=""><blockquote type="cite" style="font-family: Helvetica; font-size: 14px; 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=""><div class=""><div 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="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 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;"><br class=""></div><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;">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 class=""><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 class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(0, 132, 0);"><span class="" style="font-variant-ligatures: no-common-ligatures;"><span class="" style="color: rgb(186, 45, 162);"> </span><span class="" style="color: rgb(186, 45, 162);"> </span>// Current state of affairs</span></div></div><div class=""><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;"><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(186, 45, 162);"> let</span><span class="" style="font-variant-ligatures: no-common-ligatures;"><span class="Apple-converted-space"> </span>name:<span class="Apple-converted-space"> </span></span><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(112, 61, 170);">String</span><span class="" style="font-variant-ligatures: no-common-ligatures;"><span class="Apple-converted-space"> </span>= row.</span><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(49, 89, 93);">value</span><span class="" style="font-variant-ligatures: no-common-ligatures;">(named:<span class="Apple-converted-space"> </span></span><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(209, 47, 27);">"name"</span><span class="" style="font-variant-ligatures: no-common-ligatures;">)</span></div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;"><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(186, 45, 162);"> let</span><span class="" style="font-variant-ligatures: no-common-ligatures;"> bookCount: </span><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(112, 61, 170);">Int</span><span class="" style="font-variant-ligatures: no-common-ligatures;"> = row.</span><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(49, 89, 93);">value</span><span class="" style="font-variant-ligatures: no-common-ligatures;">(named: </span><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(209, 47, 27);">"bookCount"</span><span class="" style="font-variant-ligatures: no-common-ligatures;">)</span></div></div><div class=""><span class="" style="font-variant-ligatures: no-common-ligatures;"><div class=""><span class="" style="font-variant-ligatures: no-common-ligatures;"><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;"><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(186, 45, 162);"> let</span><span class="" style="font-variant-ligatures: no-common-ligatures;"> hasBooks: </span><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(112, 61, 170);">Bool</span><span class="" style="font-variant-ligatures: no-common-ligatures;"> = row.</span><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(49, 89, 93);">value</span><span class="" style="font-variant-ligatures: no-common-ligatures;">(named: </span><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(209, 47, 27);">"bookCount"</span><span class="" style="font-variant-ligatures: no-common-ligatures;">)</span></div><div class=""><span class="" style="font-variant-ligatures: no-common-ligatures;"><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 class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(0, 132, 0);"><span class="" style="font-variant-ligatures: no-common-ligatures;"><span class="" style="color: rgb(186, 45, 162);"> </span><span class="" style="color: rgb(186, 45, 162);"> </span>// With improved subscripts</span></div></div><div class=""><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;"><div class=""><div class="" style="margin: 0px; line-height: normal;"><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(186, 45, 162);"> let</span><span class="" style="font-variant-ligatures: no-common-ligatures;"> name: </span><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(112, 61, 170);">String</span><span class="" style="font-variant-ligatures: no-common-ligatures;"> = row</span><span class="" style="font-variant-ligatures: no-common-ligatures;">[</span><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(209, 47, 27);">"name"</span>]</div><div class="" style="margin: 0px; line-height: normal;"><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(186, 45, 162);"> let</span><span class="" style="font-variant-ligatures: no-common-ligatures;"> bookCount: </span><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(112, 61, 170);">Int</span><span class="" style="font-variant-ligatures: no-common-ligatures;"> = row</span><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(209, 47, 27);"><span class="" style="">[</span>"bookCount"</span><span class="" style="font-variant-ligatures: no-common-ligatures;">]</span></div></div><div class=""><span class="" style="font-variant-ligatures: no-common-ligatures;"><div class=""><span class="" style="font-variant-ligatures: no-common-ligatures;"><div class="" style="margin: 0px; line-height: normal;"><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(186, 45, 162);"> let</span><span class="" style="font-variant-ligatures: no-common-ligatures;"> hasBooks: </span><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(112, 61, 170);">Bool</span><span class="" style="font-variant-ligatures: no-common-ligatures;"> = row</span><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(209, 47, 27);"><span class="" style="">[</span>"bookCount"</span><span class="" style="font-variant-ligatures: no-common-ligatures;">]</span></div><div class=""><br class=""></div><div class=""><div class="" style="font-family: Helvetica; font-size: 12px;">And this requires genericity on return type.</div></div></span></div></span></div></div></div></div></div></blockquote><div style="font-family: Helvetica; font-size: 14px; 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><span style="font-family: Helvetica; font-size: 14px; 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; float: none; display: inline !important;" class="">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.</span></div></blockquote><br class=""></div><div>As long as your personal preference has no impact on return-type genericity subscripts adoption, I'm fine with it :-)</div><div><br class=""></div><div>Gwendal</div><div><br class=""></div></body></html>