<html><head><meta http-equiv="Content-Type" content="text/html charset=us-ascii"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><br class=""><div><blockquote type="cite" class=""><div class="">Am 18.01.2016 um 21:18 schrieb Douglas Gregor via swift-evolution <<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>>:</div><br class="Apple-interchange-newline"><div class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: 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="">I suggest you also look at what can be done with an existential value that hasn't been opened explicitly. Can I call "generate" on a SequenceType value, and what do I get back?</span></div></blockquote></div><br class=""><div class="">I think this should be possible as SequenceType.Generator is in a covariant position and changes covariantly with the Element type.</div><div class="">The type should use the same bounds as that of the SequenceType:</div><div class=""><br class=""></div><div class=""><div style="margin: 0px; font-size: 13px; line-height: normal; font-family: Menlo; color: rgb(131, 148, 150);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #859901" class="">var</span> zs: <span style="color: rgb(133, 153, 1);" class="">protocol<</span>SequenceType <span style="color: rgb(133, 153, 1);" class="">where</span> Generator.Element : SomeProtocol></div><div style="margin: 0px; font-size: 13px; line-height: normal; font-family: Menlo; color: rgb(88, 110, 117);" class=""><span style="color: rgb(133, 153, 1);" class="">var</span><span style="color: rgb(131, 148, 150);" class=""> gz: </span><span style="color: rgb(133, 153, 1);" class="">protocol<</span><span style="color: rgb(131, 148, 150);" class="">SequenceType.GeneratorType </span><span style="color: rgb(133, 153, 1);" class="">where</span><span style="color: rgb(131, 148, 150);" class=""> .Element : </span><span style="color: rgb(131, 148, 150);" class="">SomeProtocol</span><span style="color: rgb(131, 148, 150);" class="">> = zs.generate()</span></div><div style="margin: 0px; font-size: 13px; line-height: normal; font-family: Menlo; color: rgb(131, 148, 150);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #859901" class="">var</span> z: SomeProtocol? = gz.next()</div></div><div style="margin: 0px; font-size: 13px; line-height: normal; font-family: Menlo; color: rgb(131, 148, 150);" class=""><br class=""></div><div class="">If no bounds would have been given Element would have the type Any.</div><div class=""><br class=""></div><div class="">Should we have path-dependent types like Scala?</div><div class="">(see e.g. <a href="http://stackoverflow.com/questions/2693067/what-is-meant-by-scalas-path-dependent-types" class="">http://stackoverflow.com/questions/2693067/what-is-meant-by-scalas-path-dependent-types</a>)</div><div class=""><br class=""></div><div class=""><div style="margin: 0px; font-size: 13px; line-height: normal; font-family: Menlo; color: rgb(131, 148, 150);" class=""><span style="color: rgb(133, 153, 1);" class="">var</span> zs: <span style="color: rgb(133, 153, 1);" class="">protocol<</span>SequenceType <span style="color: rgb(133, 153, 1);" class="">where</span> Generator.Element : SomeProtocol></div><div style="margin: 0px; font-size: 13px; line-height: normal; font-family: Menlo; color: rgb(88, 110, 117);" class=""><span style="color: rgb(133, 153, 1);" class="">var</span><span style="color: rgb(131, 148, 150);" class=""> gz: zs.Generator</span><span style="color: rgb(131, 148, 150);" class=""> = zs.generate()</span></div><div style="margin: 0px; font-size: 13px; line-height: normal; font-family: Menlo; color: rgb(131, 148, 150);" class=""><span style="color: rgb(133, 153, 1);" class="">var</span> z: SomeProtocol? = gz.next()</div></div><div class=""><div style="margin: 0px; font-size: 13px; line-height: normal; font-family: Menlo; color: rgb(131, 148, 150);" class=""><span style="color: rgb(133, 153, 1);" class="">var</span> ys: <span style="color: rgb(133, 153, 1);" class="">protocol<</span>SequenceType <span style="color: rgb(133, 153, 1);" class="">where</span> Generator.Element : SomeProtocol></div><div style="margin: 0px; font-size: 13px; line-height: normal; font-family: Menlo; color: rgb(88, 110, 117);" class=""><span style="color: rgb(133, 153, 1);" class="">var</span><span style="color: rgb(131, 148, 150);" class=""> gy: ys.Generator</span><span style="color: rgb(131, 148, 150);" class=""> = gz // type error: path-dependent types ys.Generator and zs.Generator differ</span></div></div><div class=""><span style="color: rgb(131, 148, 150);" class=""><br class=""></span></div><div class="">-Thorsten</div></body></html>