<div dir="ltr">This feature (set) as sketched here by Joe is worthwhile, in my opinion. The use of catch fits in and effect neatly captures this class of behaviors.<div>+1 for `effect`</div><div>---</div><div>TJ</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Sat, Dec 12, 2015 at 4:17 AM, Joe Groff via swift-evolution <span dir="ltr"><<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word"><span class=""><br><div><blockquote type="cite"><div>On Dec 11, 2015, at 6:26 PM, Jordan Rose via swift-evolution <<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>> wrote:</div><br><div><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">Eh, I was trying to avoid grabbing another keyword, but I guess it's context-sensitive anyway.</div></div></blockquote></div><br></span><div>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><br></div><div>effect throws { @noreturn operation throw (ErrorType) -> () }</div><div>effect yields<T> { operation yield (T) -> () }</div><div>effect awaits { operation await<T> (Promise<T>) -> T }</div><div><br></div><div>and 'catch' could be generalized to let you handle any effect operations that might be performed in the body of a block:</div><div><br></div><div>class Generator<T> {</div><div><span style="white-space:pre-wrap">        </span>var generator: () yields<T> -> ()</div><div><span style="white-space:pre-wrap">        </span>func next() -> T? {</div><div><span style="white-space:pre-wrap">                </span>do {</div><div> <span style="white-space:pre-wrap">                        </span>generator()</div><div><span style="white-space:pre-wrap">                        </span>return nil</div><div><span style="white-space:pre-wrap">                </span>} catch yield (let x) {</div><div><span style="white-space:pre-wrap">                        </span>generator = currentContinuation</div><div><span style="white-space:pre-wrap">                        </span>return x</div><div><span style="white-space:pre-wrap">                </span>}</div><div><span style="white-space:pre-wrap">        </span>}</div><div>}</div><div><br></div><div>See Eff (<a href="http://www.eff-lang.org" target="_blank">http://www.eff-lang.org</a>) for an example of a language with this already implemented.</div><div><br></div><div>-Joe</div>
<img src="https://u2002410.ct.sendgrid.net/wf/open?upn=3FGfocPbgxkNkmje7djckg9Iw-2BGYY3X6RxJ1tkUXKCpdyfs-2FQ6wsPiWsasUiN34N7QpC1VqX1dhUY5BX2NCx0wGd-2B97k6MUb-2BXjdz0OsJEFjXiU-2FJXvItzEXdEWfoBELF-2BWbN8qFKHXp88-2Fi6-2F3jsyvGSQfZxOo1o4YUoIVESWrjYC9otKRm9yjFHM1LjohwwLrqm-2BMvHKqdQcjukCSmGbhP-2Frme5oHfbVHRsBGE51o-3D" alt="" width="1" height="1" border="0" style="min-height:1px!important;width:1px!important;border-width:0!important;margin-top:0!important;margin-bottom:0!important;margin-right:0!important;margin-left:0!important;padding-top:0!important;padding-bottom:0!important;padding-right:0!important;padding-left:0!important">
</div>
<br>_______________________________________________<br>
swift-evolution mailing list<br>
<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a><br>
<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br>
<br></blockquote></div><br></div>