<html><head><style>
body {
        font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
        padding:1em;
        margin:auto;
        background:#fefefe;
}

h1, h2, h3, h4, h5, h6 {
        font-weight: bold;
}

h1 {
        color: #000000;
        font-size: 28pt;
}

h2 {
        border-bottom: 1px solid #CCCCCC;
        color: #000000;
        font-size: 24px;
}

h3 {
        font-size: 18px;
}

h4 {
        font-size: 16px;
}

h5 {
        font-size: 14px;
}

h6 {
        color: #777777;
        background-color: inherit;
        font-size: 14px;
}

hr {
        height: 0.2em;
        border: 0;
        color: #CCCCCC;
        background-color: #CCCCCC;
    display: inherit;
}

p, blockquote, ul, ol, dl, li, table, pre {
        margin: 15px 0;
}

a, a:visited {
        color: #4183C4;
        background-color: inherit;
        text-decoration: none;
}

#message {
        border-radius: 6px;
        border: 1px solid #ccc;
        display:block;
        width:100%;
        height:60px;
        margin:6px 0px;
}

button, #ws {
        font-size: 12 pt;
        padding: 4px 6px;
        border-radius: 5px;
        border: 1px solid #bbb;
        background-color: #eee;
}

code, pre, #ws, #message {
        font-family: Monaco;
        font-size: 10pt;
        border-radius: 3px;
        background-color: #F8F8F8;
        color: inherit;
}

code {
        border: 1px solid #EAEAEA;
        margin: 0 2px;
        padding: 0 5px;
}

pre {
        border: 1px solid #CCCCCC;
        overflow: auto;
        padding: 4px 8px;
}

pre > code {
        border: 0;
        margin: 0;
        padding: 0;
}

#ws { background-color: #f8f8f8; }


.bloop_markdown table {
border-collapse: collapse;  
font-family: Helvetica, arial, freesans, clean, sans-serif;  
color: rgb(51, 51, 51);  
font-size: 15px; line-height: 25px;
padding: 0; }

.bloop_markdown table tr {
border-top: 1px solid #cccccc;
background-color: white;
margin: 0;
padding: 0; }
     
.bloop_markdown table tr:nth-child(2n) {
background-color: #f8f8f8; }

.bloop_markdown table tr th {
font-weight: bold;
border: 1px solid #cccccc;
margin: 0;
padding: 6px 13px; }

.bloop_markdown table tr td {
border: 1px solid #cccccc;
margin: 0;
padding: 6px 13px; }

.bloop_markdown table tr th :first-child, table tr td :first-child {
margin-top: 0; }

.bloop_markdown table tr th :last-child, table tr td :last-child {
margin-bottom: 0; }

.bloop_markdown blockquote{
  border-left: 4px solid #dddddd;
  padding: 0 15px;
  color: #777777; }
  blockquote > :first-child {
    margin-top: 0; }
  blockquote > :last-child {
    margin-bottom: 0; }

code, pre, #ws, #message {
    word-break: normal;
    word-wrap: normal;
}

hr {
    display: inherit;
}

.bloop_markdown :first-child {
    -webkit-margin-before: 0;
}

code, pre, #ws, #message {
    font-family: Menlo, Consolas, Liberation Mono, Courier, monospace;
}


.send { color:#77bb77; }
.server { color:#7799bb; }
.error { color:#AA0000; }</style></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><div class="bloop_markdown"><p>Thank you guys for all your suggestions so far.</p>

<p>I understand the idea behind the generic subscript here, they are neat and highly needed, but even this approach won’t solve my issue of clarity here.</p>

<p>The Array I extend here has an <code>Element</code> of type <code>Value</code> which is an enum that wraps other types around (part of BSON).</p>

<p>I’d have to insert a huge pattern matching switch into that generic subscript and unwrap every possible type. Don’t get me wrong, this would work, because the result type is an optional, where I just can return nil if nothing matches.</p>

<p>But again I lose the clarity from the readers prospective, because I don’t know by reading code like <code>array[at: 123] = someValue</code> what kind of subscript I’m using here. </p>

<p>As already suggested, the view workaround would result in the exact the same syntax I look for, but it has it own downsides as I already mentioned (+ every time you’d need to instantiate a new view).</p>

<p></p></div><div class="bloop_original_html"><style>body{font-family:Helvetica,Arial;font-size:13px}</style><div id="bloop_customfont" style="font-family:Helvetica,Arial;font-size:13px; color: rgba(0,0,0,1.0); margin: 0px; line-height: auto;"><br></div> <br> <div id="bloop_sign_1479460311132606976" class="bloop_sign"><div style="font-family:helvetica,arial;font-size:13px">--&nbsp;<br>Adrian Zubarev<br>Sent with Airmail</div></div> <br><p class="airmail_on">Am 18. November 2016 um 09:55:00, Haravikk (<a href="mailto:swift-evolution@haravikk.me">swift-evolution@haravikk.me</a>) schrieb:</p> <blockquote type="cite" class="clean_bq"><span><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div></div><div>



<title></title>


<div class="">Could this be addressed by allowing generic
constraints on subscripts?</div>
<div class="">For example, with methods we can currently do:</div>
<div class=""><br class=""></div>
<blockquote style="margin: 0 0 0 40px; border: none; padding: 0px;" class="">
<div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">
<div style="margin: 0px; line-height: normal;" class="">
<div style="margin: 0px; line-height: normal;" class="">
<span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">struct</span> <span style="font-variant-ligatures: no-common-ligatures" class="">Foo
{</span></div>
<div style="margin: 0px; line-height: normal;" class="">
<span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">var</span> <span style="font-variant-ligatures: no-common-ligatures" class="">values:[</span><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">Any</span><span style="font-variant-ligatures: no-common-ligatures" class="">] =
[]</span></div>
<div style="margin: 0px; line-height: normal; min-height: 13px;" class=""><br class=""></div>
<div style="margin: 0px; line-height: normal;" class="">
<span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">func</span> <span style="font-variant-ligatures: no-common-ligatures" class="">get&lt;T&gt;(at:</span><span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">Int</span><span style="font-variant-ligatures: no-common-ligatures" class="">)
-&gt;</span> <span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">T</span><span style="font-variant-ligatures: no-common-ligatures" class="">?
{</span></div>
<div style="margin: 0px; line-height: normal;" class="">
<span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">return</span> <span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">values</span><span style="font-variant-ligatures: no-common-ligatures" class="">.</span><span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">indices</span><span style="font-variant-ligatures: no-common-ligatures" class="">.</span><span style="font-variant-ligatures: no-common-ligatures; color: #3d1d81" class="">contains</span><span style="font-variant-ligatures: no-common-ligatures" class="">(at)
?</span> <span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">values</span><span style="font-variant-ligatures: no-common-ligatures" class="">[at]</span>
<span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">as</span><span style="font-variant-ligatures: no-common-ligatures" class="">?</span>
<span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">T</span> <span style="font-variant-ligatures: no-common-ligatures" class="">:</span>
<span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">nil</span></div>
<div style="margin: 0px; line-height: normal;" class="">
<span style="font-variant-ligatures: no-common-ligatures" class="">}</span></div>
<div style="margin: 0px; line-height: normal; min-height: 13px;" class=""><br class=""></div>
<div style="margin: 0px; line-height: normal;" class="">
<span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">func</span> <span style="font-variant-ligatures: no-common-ligatures" class="">get&lt;T&gt;(at:</span><span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">Int</span><span style="font-variant-ligatures: no-common-ligatures" class="">, as
theType:</span><span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">T</span><span style="font-variant-ligatures: no-common-ligatures" class="">.Type)
-&gt;</span> <span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">T</span><span style="font-variant-ligatures: no-common-ligatures" class="">?
{</span></div>
<div style="margin: 0px; line-height: normal;" class="">
<span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">return</span> <span style="font-variant-ligatures: no-common-ligatures" class="">values.indices.contains(at) ? values[at]</span> <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">as</span><span style="font-variant-ligatures: no-common-ligatures" class="">?</span>
<span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">T</span> <span style="font-variant-ligatures: no-common-ligatures" class="">:</span>
<span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">nil</span></div>
<div style="margin: 0px; line-height: normal;" class="">
<span style="font-variant-ligatures: no-common-ligatures" class="">}</span></div>
<div style="margin: 0px; line-height: normal; min-height: 13px;" class=""><br class=""></div>
<div style="margin: 0px; line-height: normal;" class="">
<span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">mutating</span> <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">func</span> <span style="font-variant-ligatures: no-common-ligatures" class="">set&lt;T&gt;(at:</span><span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">Int</span><span style="font-variant-ligatures: no-common-ligatures" class="">,
to:</span><span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">T</span><span style="font-variant-ligatures: no-common-ligatures" class="">)
{</span></div>
<div style="margin: 0px; line-height: normal;" class="">
<span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">if</span> <span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">values</span><span style="font-variant-ligatures: no-common-ligatures" class="">.</span><span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">indices</span><span style="font-variant-ligatures: no-common-ligatures" class="">.</span><span style="font-variant-ligatures: no-common-ligatures; color: #3d1d81" class="">contains</span><span style="font-variant-ligatures: no-common-ligatures" class="">(at)
{</span> <span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">values</span><span style="font-variant-ligatures: no-common-ligatures" class="">[at] = to
}</span></div>
<div style="margin: 0px; line-height: normal;" class="">
<span style="font-variant-ligatures: no-common-ligatures" class="">}</span></div>
<div style="margin: 0px; line-height: normal;" class="">
<span style="font-variant-ligatures: no-common-ligatures" class="">}</span></div>
<div style="margin: 0px; line-height: normal; min-height: 13px;" class=""><br class=""></div>
<div style="margin: 0px; line-height: normal;" class="">
<span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">let</span> <span style="font-variant-ligatures: no-common-ligatures" class="">foo =</span>
<span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">Foo</span><span style="font-variant-ligatures: no-common-ligatures" class="">(values:
[</span><span style="font-variant-ligatures: no-common-ligatures; color: #272ad8" class="">1.5</span><span style="font-variant-ligatures: no-common-ligatures" class="">,</span>
<span style="font-variant-ligatures: no-common-ligatures; color: #272ad8" class="">2.5</span><span style="font-variant-ligatures: no-common-ligatures" class="">,</span>
<span style="font-variant-ligatures: no-common-ligatures; color: #272ad8" class="">3.5</span><span style="font-variant-ligatures: no-common-ligatures" class="">,</span>
<span style="font-variant-ligatures: no-common-ligatures; color: #272ad8" class="">1</span><span style="font-variant-ligatures: no-common-ligatures" class="">,</span>
<span style="font-variant-ligatures: no-common-ligatures; color: #272ad8" class="">2</span><span style="font-variant-ligatures: no-common-ligatures" class="">,</span>
<span style="font-variant-ligatures: no-common-ligatures; color: #272ad8" class="">3</span><span style="font-variant-ligatures: no-common-ligatures" class="">])</span></div>
<div style="margin: 0px; line-height: normal;" class="">
<span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">let</span> <span style="font-variant-ligatures: no-common-ligatures" class="">a =
foo.get(at:</span> <span style="font-variant-ligatures: no-common-ligatures; color: #272ad8" class="">0</span><span style="font-variant-ligatures: no-common-ligatures" class="">, as:
Double.</span><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">self</span><span style="font-variant-ligatures: no-common-ligatures" class="">)</span></div>
<div style="margin: 0px; line-height: normal;" class="">
<span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">let</span> <span style="font-variant-ligatures: no-common-ligatures" class="">b:</span><span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">Double</span> <span style="font-variant-ligatures: no-common-ligatures" class="">=</span>
<span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">foo</span><span style="font-variant-ligatures: no-common-ligatures" class="">.</span><span style="font-variant-ligatures: no-common-ligatures; color: #31595d" class="">get</span><span style="font-variant-ligatures: no-common-ligatures" class="">(at:</span>
<span style="font-variant-ligatures: no-common-ligatures; color: #272ad8" class="">1</span><span style="font-variant-ligatures: no-common-ligatures" class="">)!</span></div>
<div style="margin: 0px; line-height: normal;" class="">
<span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">let</span> <span style="font-variant-ligatures: no-common-ligatures" class="">c:</span><span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">Int</span><span style="font-variant-ligatures: no-common-ligatures" class="">? =</span>
<span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">foo</span><span style="font-variant-ligatures: no-common-ligatures" class="">.</span><span style="font-variant-ligatures: no-common-ligatures; color: #31595d" class="">get</span><span style="font-variant-ligatures: no-common-ligatures" class="">(at:</span>
<span style="font-variant-ligatures: no-common-ligatures; color: #272ad8" class="">2</span><span style="font-variant-ligatures: no-common-ligatures" class="">)</span></div>
<div style="margin: 0px; line-height: normal;" class="">
<span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">let</span> <span style="font-variant-ligatures: no-common-ligatures" class="">d =
foo.get(at:</span> <span style="font-variant-ligatures: no-common-ligatures; color: #272ad8" class="">3</span><span style="font-variant-ligatures: no-common-ligatures" class="">, as:
Double.</span><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">self</span><span style="font-variant-ligatures: no-common-ligatures" class="">)</span></div>
<div style="margin: 0px; line-height: normal;" class="">
<span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">let</span> <span style="font-variant-ligatures: no-common-ligatures" class="">e:</span><span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">Int</span> <span style="font-variant-ligatures: no-common-ligatures" class="">=</span>
<span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">foo</span><span style="font-variant-ligatures: no-common-ligatures" class="">.</span><span style="font-variant-ligatures: no-common-ligatures; color: #31595d" class="">get</span><span style="font-variant-ligatures: no-common-ligatures" class="">(at:</span>
<span style="font-variant-ligatures: no-common-ligatures; color: #272ad8" class="">4</span><span style="font-variant-ligatures: no-common-ligatures" class="">)!</span></div>
<div style="margin: 0px; line-height: normal;" class="">
<span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">let</span> <span style="font-variant-ligatures: no-common-ligatures" class="">f =
foo.get(at:</span> <span style="font-variant-ligatures: no-common-ligatures; color: #272ad8" class="">5</span><span style="font-variant-ligatures: no-common-ligatures" class="">, as:
Int.</span><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">self</span><span style="font-variant-ligatures: no-common-ligatures" class="">)</span></div>
</div>
</div>
</blockquote>
<div class="">
<div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;" class=""></div>
i.e- the type is inferred from the call-site either with an
explicit variable type, or by passing in the expected type as the
second argument, which I think is a pretty neat way to do it.</div>
<div class=""><br class=""></div>
<div class="">If we could do the same with subscripts we could do
something like:</div>
<div class=""><br class=""></div>
<blockquote style="margin: 0 0 0 40px; border: none; padding: 0px;" class="">
<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: #bb2ca2" class="">struct</span> <span style="font-variant-ligatures: no-common-ligatures" class="">Foo
{</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: #bb2ca2" class="">var</span> <span style="font-variant-ligatures: no-common-ligatures" class="">values:[</span><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">Any</span><span style="font-variant-ligatures: no-common-ligatures" class="">] =
[]</span></div>
</div>
<div class="">
<div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;" class=""><br class=""></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: #bb2ca2" class="">subscript</span><span style="font-variant-ligatures: no-common-ligatures" class="">&lt;T&gt;(</span><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">_</span> <span style="font-variant-ligatures: no-common-ligatures" class="">at:Int)
-&gt; T? {</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" class="">get {</span> <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">return</span> <span style="font-variant-ligatures: no-common-ligatures" class="">values.indices.contains(at) ? values[at]</span> <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">as</span><span style="font-variant-ligatures: no-common-ligatures" class="">? T :</span>
<span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">nil</span> <span style="font-variant-ligatures: no-common-ligatures" class="">}</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" class="">set {</span> <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">if</span> <span style="font-variant-ligatures: no-common-ligatures" class="">values.indices.contains(at) { values[at] = newValue }
}</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" class="">}</span></div>
</div>
<div class="">
<div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;" class=""><br class=""></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: #bb2ca2" class="">subscript</span><span style="font-variant-ligatures: no-common-ligatures" class="">&lt;T&gt;(</span><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">_</span> <span style="font-variant-ligatures: no-common-ligatures" class="">at:Int, as
theType:T.Type) -&gt; T? {</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: #bb2ca2" class="">return</span> <span style="font-variant-ligatures: no-common-ligatures" class="">values.indices.contains(at) ? values[at]</span> <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">as</span><span style="font-variant-ligatures: no-common-ligatures" class="">? T :</span>
<span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">nil</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" class="">}</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" class="">}</span></div>
</div>
<div class="">
<div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;" class=""><br class=""></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: #bb2ca2" class="">let</span> <span style="font-variant-ligatures: no-common-ligatures" class="">foo =</span>
<span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">Foo</span><span style="font-variant-ligatures: no-common-ligatures" class="">(values:
[</span><span style="font-variant-ligatures: no-common-ligatures; color: #272ad8" class="">1.5</span><span style="font-variant-ligatures: no-common-ligatures" class="">,</span>
<span style="font-variant-ligatures: no-common-ligatures; color: #272ad8" class="">2.5</span><span style="font-variant-ligatures: no-common-ligatures" class="">,</span>
<span style="font-variant-ligatures: no-common-ligatures; color: #272ad8" class="">3.5</span><span style="font-variant-ligatures: no-common-ligatures" class="">,</span>
<span style="font-variant-ligatures: no-common-ligatures; color: #272ad8" class="">1</span><span style="font-variant-ligatures: no-common-ligatures" class="">,</span>
<span style="font-variant-ligatures: no-common-ligatures; color: #272ad8" class="">2</span><span style="font-variant-ligatures: no-common-ligatures" class="">,</span>
<span style="font-variant-ligatures: no-common-ligatures; color: #272ad8" class="">3</span><span style="font-variant-ligatures: no-common-ligatures" class="">])</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: #bb2ca2" class="">let</span> <span style="font-variant-ligatures: no-common-ligatures" class="">a =</span>
<span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">foo</span><span style="font-variant-ligatures: no-common-ligatures" class="">[</span><span style="font-variant-ligatures: no-common-ligatures; color: #272ad8" class="">0</span><span style="font-variant-ligatures: no-common-ligatures" class="">, as:</span>
<span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">Double</span><span style="font-variant-ligatures: no-common-ligatures" class=""><span style="font-variant-ligatures: no-common-ligatures;" class="">.</span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(187, 44, 162);" class="">self</span>]</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: #bb2ca2" class="">let</span> <span style="font-variant-ligatures: no-common-ligatures" class="">b:</span><span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">Double</span> <span style="font-variant-ligatures: no-common-ligatures" class="">=</span>
<span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">foo</span><span style="font-variant-ligatures: no-common-ligatures" class="">[</span><span style="font-variant-ligatures: no-common-ligatures; color: #272ad8" class="">1</span><span style="font-variant-ligatures: no-common-ligatures" class="">]!</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: #bb2ca2" class="">let</span> <span style="font-variant-ligatures: no-common-ligatures" class="">c:</span><span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">Int</span><span style="font-variant-ligatures: no-common-ligatures" class="">? =</span>
<span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">foo</span><span style="font-variant-ligatures: no-common-ligatures" class="">[</span><span style="font-variant-ligatures: no-common-ligatures; color: #272ad8" class="">2</span><span style="font-variant-ligatures: no-common-ligatures" class="">]</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: #bb2ca2" class="">let</span> <span style="font-variant-ligatures: no-common-ligatures" class="">d =</span>
<span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">foo</span><span style="font-variant-ligatures: no-common-ligatures" class="">[</span><span style="font-variant-ligatures: no-common-ligatures; color: #272ad8" class="">3</span><span style="font-variant-ligatures: no-common-ligatures" class="">, as:</span>
<span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">Double</span><span style="font-variant-ligatures: no-common-ligatures" class=""><span style="font-variant-ligatures: no-common-ligatures;" class="">.</span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(187, 44, 162);" class="">self</span>]</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: #bb2ca2" class="">let</span> <span style="font-variant-ligatures: no-common-ligatures" class="">e:</span><span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">Int</span> <span style="font-variant-ligatures: no-common-ligatures" class="">=</span>
<span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">foo</span><span style="font-variant-ligatures: no-common-ligatures" class="">[</span><span style="font-variant-ligatures: no-common-ligatures; color: #272ad8" class="">4</span><span style="font-variant-ligatures: no-common-ligatures" class="">]!</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: #bb2ca2" class="">let</span> <span style="font-variant-ligatures: no-common-ligatures" class="">f =</span>
<span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">foo</span><span style="font-variant-ligatures: no-common-ligatures" class="">[</span><span style="font-variant-ligatures: no-common-ligatures; color: #272ad8" class="">5</span><span style="font-variant-ligatures: no-common-ligatures" class="">, as:</span>
<span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">Int</span><span style="font-variant-ligatures: no-common-ligatures" class=""><span style="font-variant-ligatures: no-common-ligatures;" class="">.</span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(187, 44, 162);" class="">self</span>]</span></div>
</div>
</blockquote>
<div class=""><br class=""></div>
<div class="">Are generic constraints on subscripts part of the
generics manifesto?</div>
<div class=""><br class=""></div>
<div class="">
<div>
<blockquote type="cite" class="">
<div class="">On 17 Nov 2016, at 20:14, Adrian Zubarev via
swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>&gt; wrote:</div>
<br class="Apple-interchange-newline">
<div class="">
<div class="bloop_markdown" 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; background-color: rgb(254, 254, 254);">
<p style="margin: 15px 0px; -webkit-margin-before: 0px;" class="">
Dear Swift community,</p>
<p style="margin: 15px 0px;" class="">while building a framework
for BSON I had the following idea.</p>
<p style="margin: 15px 0px;" class="">Here is a snippet of some
code I do have in my module:</p>
<pre style="margin: 15px 0px; font-family: Menlo, Consolas, 'Liberation Mono', Courier, monospace; font-size: 10pt; border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; background-color: rgb(248, 248, 248); color: inherit; border: 1px solid rgb(204, 204, 204); overflow: auto; padding: 4px 8px; word-break: normal; word-wrap: normal;" class=""><code class="swift" style="font-family: Menlo, Consolas, 'Liberation Mono', Courier, monospace; font-size: 10pt; border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; background-color: rgb(248, 248, 248); color: inherit; border: 0px; margin: 0px; padding: 0px; word-break: normal; word-wrap: normal; -webkit-margin-before: 0px;">extension Array where Element == Document.Value {
          
    public func double(at index: Int) -&gt; Double? {
          
        guard self.startIndex &lt;= index &amp;&amp; index &lt; self.endIndex else { return nil }
          
        if case .double(let double) = self[index] {
              
            return double
        }
        return nil
    }
      
    …
}
</code></pre>
<p style="margin: 15px 0px;" class="">This function is used to
query the array and check if the element at the given index is of a
specific type. Now I would like also to implement a semi-schema
setter.</p>
<p style="margin: 15px 0px;" class="">The problem that I see, is
the ugliness of the<span class="Apple-converted-space">&nbsp;</span><code style="font-family: Menlo, Consolas, 'Liberation Mono', Courier, monospace; font-size: 10pt; border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; background-color: rgb(248, 248, 248); color: inherit; border: 1px solid rgb(234, 234, 234); margin: 0px 2px; padding: 0px 5px; word-break: normal; word-wrap: normal; -webkit-margin-before: 0px;" class="">subscript</code><span class="Apple-converted-space">&nbsp;</span>I’d create.</p>
<p style="margin: 15px 0px;" class="">Currently the code would read
nicely<span class="Apple-converted-space">&nbsp;</span><code style="font-family: Menlo, Consolas, 'Liberation Mono', Courier, monospace; font-size: 10pt; border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; background-color: rgb(248, 248, 248); color: inherit; border: 1px solid rgb(234, 234, 234); margin: 0px 2px; padding: 0px 5px; word-break: normal; word-wrap: normal; -webkit-margin-before: 0px;" class="">let d = array.double(at: 42)</code>, but after change to
a<span class="Apple-converted-space">&nbsp;</span><code style="font-family: Menlo, Consolas, 'Liberation Mono', Courier, monospace; font-size: 10pt; border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; background-color: rgb(248, 248, 248); color: inherit; border: 1px solid rgb(234, 234, 234); margin: 0px 2px; padding: 0px 5px; word-break: normal; word-wrap: normal;" class="">subscript</code><span class="Apple-converted-space">&nbsp;</span>the API would look
odd<span class="Apple-converted-space">&nbsp;</span><code style="font-family: Menlo, Consolas, 'Liberation Mono', Courier, monospace; font-size: 10pt; border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; background-color: rgb(248, 248, 248); color: inherit; border: 1px solid rgb(234, 234, 234); margin: 0px 2px; padding: 0px 5px; word-break: normal; word-wrap: normal;" class="">array[doubleAt: 42] = 5.0</code>.</p>
<p style="margin: 15px 0px;" class="">Don’t get me wrong here, I
also have methods with larger names like<span class="Apple-converted-space">&nbsp;</span><code style="font-family: Menlo, Consolas, 'Liberation Mono', Courier, monospace; font-size: 10pt; border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; background-color: rgb(248, 248, 248); color: inherit; border: 1px solid rgb(234, 234, 234); margin: 0px 2px; padding: 0px 5px; word-break: normal; word-wrap: normal; -webkit-margin-before: 0px;" class="">public func scopedJavaScript(at index: Int) -&gt;
…</code>. You can easily imagine that such subscripts would look
ugly<span class="Apple-converted-space">&nbsp;</span><code style="font-family: Menlo, Consolas, 'Liberation Mono', Courier, monospace; font-size: 10pt; border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; background-color: rgb(248, 248, 248); color: inherit; border: 1px solid rgb(234, 234, 234); margin: 0px 2px; padding: 0px 5px; word-break: normal; word-wrap: normal;" class="">array[scopedJavaScriptAt: 123] = …</code>.</p>
<p style="margin: 15px 0px;" class="">I propose to align the design
of subscript with functions where one could optionally give
subscript a name.</p>
<pre style="margin: 15px 0px; font-family: Menlo, Consolas, 'Liberation Mono', Courier, monospace; font-size: 10pt; border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; background-color: rgb(248, 248, 248); color: inherit; border: 1px solid rgb(204, 204, 204); overflow: auto; padding: 4px 8px; word-break: normal; word-wrap: normal;" class=""><code class="swift" style="font-family: Menlo, Consolas, 'Liberation Mono', Courier, monospace; font-size: 10pt; border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; background-color: rgb(248, 248, 248); color: inherit; border: 0px; margin: 0px; padding: 0px; word-break: normal; word-wrap: normal; -webkit-margin-before: 0px;">func name(label parameter: Type) -&gt; ReturnType

subscript optionalName(label parameter: Type) -&gt; ReturnType
</code></pre>
<p style="margin: 15px 0px;" class="">This change would make my API
nice and clean.<span class="Apple-converted-space">&nbsp;</span><code style="font-family: Menlo, Consolas, 'Liberation Mono', Courier, monospace; font-size: 10pt; border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; background-color: rgb(248, 248, 248); color: inherit; border: 1px solid rgb(234, 234, 234); margin: 0px 2px; padding: 0px 5px; word-break: normal; word-wrap: normal; -webkit-margin-before: 0px;" class="">array.scopedJavaScript[at: 213] = …</code></p>
<p style="margin: 15px 0px;" class="">This also might be the
opportunity to rethink the labeling rule on subscripts, but this
shall not be the main focus of this pitch.</p>
<div style="margin: 15px 0px;" class=""><br class="webkit-block-placeholder"></div>
</div>
<div class="bloop_original_html" 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; background-color: rgb(254, 254, 254);">
<div id="bloop_customfont" style="font-family: Helvetica, Arial; font-size: 13px; margin: 0px;" class=""><br class=""></div>
<br class="">
<div id="bloop_sign_1479412498260118016" class="bloop_sign">
<div style="font-family: helvetica, arial; font-size: 13px;" class="">--&nbsp;<br class="">
Adrian Zubarev<br class="">
Sent with Airmail</div>
</div>
</div>
<div class="bloop_markdown" 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; background-color: rgb(254, 254, 254);">
<div style="margin: 15px 0px; -webkit-margin-before: 0px;" class=""><br class="webkit-block-placeholder"></div>
</div>
<span 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; background-color: rgb(254, 254, 254); float: none; display: inline !important;" class="">_______________________________________________</span><br 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; background-color: rgb(254, 254, 254);" class="">
<span 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; background-color: rgb(254, 254, 254); float: none; display: inline !important;" class="">swift-evolution mailing list</span><br 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; background-color: rgb(254, 254, 254);" class="">
<a href="mailto:swift-evolution@swift.org" style="color: rgb(65, 131, 196); background-color: rgb(254, 254, 254); text-decoration: none; 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;" class="">swift-evolution@swift.org</a><br 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; background-color: rgb(254, 254, 254);" class="">
<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" style="color: rgb(65, 131, 196); background-color: rgb(254, 254, 254); text-decoration: none; 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;" class="">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br 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; background-color: rgb(254, 254, 254);" class=""></div>
</blockquote>
</div>
<br class=""></div>


</div></div></span></blockquote></div><div class="bloop_markdown"><p></p></div></body></html>