<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 class="">I really like this form… </div><div class=""><br class=""></div><div class=""> func countToTen() -> yields Int { yield 1; yield 2 }</div><div class=""><br class=""></div><div class="">It reads well and states clearly what it’s intent is.</div><div class=""><br class=""></div><div class="">Works/reads well with ‘throws’...</div><div class=""><br class=""></div><div class=""> func countToTen() throws -> yields Int {}</div><div class=""><br class=""></div><div class="">And there must be some advantage to claiming two keywords that are nearly identical, ‘yield’ & ‘yields’.</div><div class=""><br class=""><div><blockquote type="cite" class=""><div class="">On Dec 11, 2015, at 8:45 PM, Alex Gordon via swift-evolution <<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" 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;" class="">IMO the yields should be literally *in* the return type. The present state of things is<div class=""><br class=""></div><div class="">fn countToTen() -> CountToTenGenerator</div><div class=""><br class=""></div><div class="">Generator functions are normal functions. What is special about them is that instead of returning a named type such as "CountToTenGenerator", the compiler replaces the return type with an anonymous type conforming to GeneratorType. So conceptually it's the return type that is special, not the function.</div><div class=""><br class=""></div><div class="">Try either one of these for size</div><div class=""><br class=""></div><div class=""><div class=""><div class=""><div class=""><div class="">fn countToTen() -> yields Int {</div></div><div class="">fn countToTen() -> yields<Int> {</div></div></div><div class=""><br class=""></div><div class="">- Alex</div></div></div><div class="gmail_extra" 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;"><br class=""><div class="gmail_quote">On Sat, Dec 12, 2015 at 3:17 AM, Joe Groff via swift-evolution<span class="Apple-converted-space"> </span><span dir="ltr" class=""><<a href="mailto:swift-evolution@swift.org" target="_blank" class="">swift-evolution@swift.org</a>></span><span class="Apple-converted-space"> </span>wrote:<br class=""><blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: solid; padding-left: 1ex;"><div style="word-wrap: break-word;" class=""><br class=""><div class=""><blockquote type="cite" class=""><div class="">On Dec 11, 2015, at 6:26 PM, Jordan Rose via swift-evolution <<a href="mailto:swift-evolution@swift.org" target="_blank" class="">swift-evolution@swift.org</a>> wrote:</div><br class=""><div class=""><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px;" class="">Eh, I was trying to avoid grabbing another keyword, but I guess it's context-sensitive anyway.</div></div></blockquote></div><br class=""><div class="">I've thought about this some. It might not have to be a keyword, if this were a generalized language feature. Anything that interrupts control flow and optionally resumes it later, such as 'throws', 'yields', and potentially also 'async', could be implemented as instances of algebraic effects. As a rough sketch of an idea, you could declare an effect and its operations:</div><div class=""><br class=""></div><div class="">effect throws { @noreturn operation throw (ErrorType) -> () }</div><div class="">effect yields<T> { operation yield (T) -> () }</div><div class="">effect awaits { operation await<T> (Promise<T>) -> T }</div><div class=""><br class=""></div><div class="">and 'catch' could be generalized to let you handle any effect operations that might be performed in the body of a block:</div><div class=""><br class=""></div><div class="">class Generator<T> {</div><div class=""><span style="white-space: pre-wrap;" class="">        </span>var generator: () yields<T> -> ()</div><div class=""><span style="white-space: pre-wrap;" class="">        </span>func next() -> T? {</div><div class=""><span style="white-space: pre-wrap;" class="">                </span>do {</div><div class=""> <span style="white-space: pre-wrap;" class="">                        </span>generator()</div><div class=""><span style="white-space: pre-wrap;" class="">                        </span>return nil</div><div class=""><span style="white-space: pre-wrap;" class="">                </span>} catch yield (let x) {</div><div class=""><span style="white-space: pre-wrap;" class="">                        </span>generator = currentContinuation</div><div class=""><span style="white-space: pre-wrap;" class="">                        </span>return x</div><div class=""><span style="white-space: pre-wrap;" class="">                </span>}</div><div class=""><span style="white-space: pre-wrap;" class="">        </span>}</div><div class="">}</div><div class=""><br class=""></div><div class="">See Eff (<a href="http://www.eff-lang.org/" target="_blank" class="">http://www.eff-lang.org</a>) for an example of a language with this already implemented.</div><div class=""><br class=""></div><div class="">-Joe</div><img src="https://u2002410.ct.sendgrid.net/wf/open?upn=ufQ1sKmNNtjEC-2BBUON-2BgZPd8t-2F4PFTin0qlI9lRM0AnYWfPJx9MdrGP2MyJiuvNNJfgCjcQYQF66UTHp3zeXCancTzUtH0fvnWnk5CCz631pBC466usXVjp5YpiuwopqWj6-2B8J-2BkQk-2BxKHMaBkE8fLRqEq05VrZdRtUpR9gzRuWaDyWzW6G5uX0bsNnUSwlzwta1vE0QfLVCdGyYIbA-2FzmyjvmOUuePIeVb4CkYhg1Y-3D" alt="" width="1" height="1" border="0" style="min-height: 1px !important; width: 1px !important; border-width: 0px !important; margin: 0px !important; padding: 0px !important;" class=""></div><br class="">_______________________________________________<br class="">swift-evolution mailing list<br class=""><a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a><br class=""><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank" class="">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br class=""><br class=""></blockquote></div><br class=""></div><img src="https://u2002410.ct.sendgrid.net/wf/open?upn=1Ry8ov4zuU66O51YNcjYWfjvikwAt9-2B1tu4XXp7LfcisFcQCgdjP6YCg63QyX5TStTSoMvWitAm88TibTcRy0mBoNG133IeWFjuGfuCBS0tq8Bru69krphtD2d9-2BdFpOP1Ck4cI80OPW1IFR1YQYOayEWLjsktqINcRbnuwY7TYJC851Xd7OfEbpq-2BEBNbJ4p8Ae3E0LvuQBjU6H0BPBnw-3D-3D" alt="" width="1" height="1" border="0" 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; height: 1px !important; width: 1px !important; border-width: 0px !important; margin: 0px !important; padding: 0px !important;" 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=""><span class="Apple-converted-space"> </span>_______________________________________________</span><br 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;" 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="">swift-evolution mailing list</span><br 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;" class=""><a href="mailto:swift-evolution@swift.org" 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;" class="">swift-evolution@swift.org</a><br 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;" class=""><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" 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;" class="">https://lists.swift.org/mailman/listinfo/swift-evolution</a></div></blockquote></div><br class=""></div></body></html>