<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=""><br class=""><div><blockquote type="cite" class=""><div class="">On 12 Mar 2017, at 09:11, Xiaodi Wu <<a href="mailto:xiaodi.wu@gmail.com" class="">xiaodi.wu@gmail.com</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-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class="">On Sun, Mar 12, 2017 at 3:02 AM, Karl Wagner<span class="Apple-converted-space"> </span><span dir="ltr" class=""><<a href="mailto:razielim@gmail.com" target="_blank" class="">razielim@gmail.com</a>></span><span class="Apple-converted-space"> </span>wrote:<br class=""><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left-width: 1px; border-left-style: solid; border-left-color: rgb(204, 204, 204); padding-left: 1ex;"><div style="word-wrap: break-word;" class=""><div class=""><div class="h5"><br class=""><div class=""><blockquote type="cite" class=""><div class="">On 12 Mar 2017, at 08:50, Xiaodi Wu <<a href="mailto:xiaodi.wu@gmail.com" target="_blank" class="">xiaodi.wu@gmail.com</a>> wrote:</div><br class="m_4681716977856857885Apple-interchange-newline"><div class=""><div dir="ltr" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px;" class="">On Sun, Mar 12, 2017 at 1:39 AM, Karl Wagner<span class="m_4681716977856857885Apple-converted-space"> </span><span dir="ltr" class=""><<a href="mailto:razielim@gmail.com" target="_blank" class="">razielim@gmail.com</a>></span><span class="m_4681716977856857885Apple-converted-space"> </span>wr<wbr class="">ote:<br class=""><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left-width: 1px; border-left-style: solid; border-left-color: rgb(204, 204, 204); padding-left: 1ex;"><div style="word-wrap: break-word;" class=""><span class="m_4681716977856857885gmail-"><br class=""><div class=""><blockquote type="cite" class=""><div class="">On 12 Mar 2017, at 08:21, Xiaodi Wu <<a href="mailto:xiaodi.wu@gmail.com" target="_blank" class="">xiaodi.wu@gmail.com</a>> wrote:</div><br class="m_4681716977856857885gmail-m_-5255648766755841190Apple-interchange-newline"><div class=""><div dir="ltr" class="">Sorry, I'm confused. The following works:<div class=""><br class=""></div><div class="">```</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: rgb(186, 45, 162);" class="">protocol</span><span style="font-variant-ligatures: no-common-ligatures;" class=""><span class="m_4681716977856857885Apple-converted-space"> </span>Promise {</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: menlo; color: rgb(186, 45, 162);" class=""><span style="font-variant-ligatures: no-common-ligatures;" class=""> <span class="m_4681716977856857885Apple-converted-space"> </span></span><span style="font-variant-ligatures: no-common-ligatures;" class="">associatedtype</span><span style="font-variant-ligatures: no-common-ligatures;" class=""><span class="m_4681716977856857885Apple-converted-space"> </span>Result</span></div><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 style="margin: 0px; font-size: 11px; line-height: normal; font-family: menlo; min-height: 13px;" class=""><span style="font-variant-ligatures: no-common-ligatures;" class=""></span><br class=""></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: rgb(186, 45, 162);" class="">protocol</span><span style="font-variant-ligatures: no-common-ligatures;" class=""><span class="m_4681716977856857885Apple-converted-space"> </span>Scanner {</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures;" class=""> <span class="m_4681716977856857885Apple-converted-space"> </span></span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(186, 45, 162);" class="">associatedtype</span><span style="font-variant-ligatures: no-common-ligatures;" class=""><span class="m_4681716977856857885Apple-converted-space"> </span>ScannerPromis<wbr class="">e : Promise</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures;" class=""> <span class="m_4681716977856857885Apple-converted-space"> </span></span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(186, 45, 162);" class="">func</span><span style="font-variant-ligatures: no-common-ligatures;" class=""><span class="m_4681716977856857885Apple-converted-space"> </span>frobnicate<T>(</span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(186, 45, 162);" class="">_</span><span style="font-variant-ligatures: no-common-ligatures;" class="">:<span class="m_4681716977856857885Apple-converted-space"> </span></span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(79, 129, 135);" class="">T</span><span style="font-variant-ligatures: no-common-ligatures;" class="">) -> ScannerPromise</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures;" class=""> <span class="m_4681716977856857885Apple-converted-space"> </span></span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(186, 45, 162);" class="">where</span><span style="font-variant-ligatures: no-common-ligatures;" class=""><span class="m_4681716977856857885Apple-converted-space"> </span>ScannerPromise.Result ==<span class="m_4681716977856857885Apple-converted-space"> </span></span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(79, 129, 135);" class="">T</span></div><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><div class=""><br class=""></div><div class="">Why does it matter if `ScannerPromise` is generic or not?</div><div class="gmail_extra"><br class=""></div></div></div></blockquote></div><br class=""></span><div class="">That’s some pretty strange syntax. I admit I didn’t even try that. ScannerPromise would necessarily have to be generic in this context, because I want to bind one of its associated types to a generic parameter from a function. There is no way a non-generic type could do that.</div><div class=""><br class=""></div><div class="">That said, even though the compiler accepts your code, it doesn’t seem to actually work:</div><div class=""><br class=""></div><blockquote style="margin: 0px 0px 0px 40px; border: none; padding: 0px;" class=""><div class=""><div class=""><font face="Courier" class="">protocol Promise {</font></div></div><div class=""><div class=""><font face="Courier" class=""> <span class="m_4681716977856857885Apple-converted-space"> </span>associatedtype Result</font></div></div><div class=""><div class=""><font face="Courier" class=""> <span class="m_4681716977856857885Apple-converted-space"> </span>func await() -> Result</font></div></div><span class="m_4681716977856857885gmail-"><div class=""><div class=""><font face="Courier" class="">}</font></div></div><div class=""><div class=""><font face="Courier" class=""><br class=""></font></div></div><div class=""><div class=""><font face="Courier" class="">protocol Scanner {</font></div></div><div class=""><div class=""><font face="Courier" class=""> <span class="m_4681716977856857885Apple-converted-space"> </span>associatedtype ScannerPromise : Promise</font></div></div><div class=""><div class=""><font face="Courier" class=""> <span class="m_4681716977856857885Apple-converted-space"> </span>func frobnicate<T>(_: T) -> ScannerPromise</font></div></div><div class=""><div class=""><font face="Courier" class=""> <span class="m_4681716977856857885Apple-converted-space"> </span>where ScannerPromise.Result == T</font></div></div><div class=""><div class=""><font face="Courier" class="">}</font></div></div><div class=""><div class=""><font face="Courier" class=""><br class=""></font></div></div></span><div class=""><div class=""><font face="Courier" class="">func use<S: Scanner, T>(_ s: S, _ t: T) -> T {</font></div></div><div class=""><div class=""><font face="Courier" class=""><span class="m_4681716977856857885gmail-m_-5255648766755841190Apple-tab-span" style="white-space: pre-wrap;">        </span>return s.frobnicate(t).await()</font></div></div><div class=""><div class=""><font face="Courier" class="">}</font></div></div></blockquote><div class=""><div class=""><span class="m_4681716977856857885gmail-m_-5255648766755841190Apple-tab-span" style="white-space: pre-wrap;">        </span><span class="m_4681716977856857885Apple-converted-space"> </span> </div></div><div class=""><br class=""></div><div class="">3.0.2: Segfault</div><div class=""><br class=""></div><div class="">3.1:</div><div class=""><br class=""></div><div class="">error: repl.swift:13:14: error: cannot invoke 'frobnicate' with an argument list of type '(T)'<br class=""> return s.frobnicate(t).await()<br class=""> ^<br class=""><br class="">repl.swift:13:14: note: expected an argument list of type '(T)'<br class=""> return s.frobnicate(t).await()</div></div></blockquote><div class=""><br class=""></div><div class="">That's because your `T` in `use` has no relationship with your `T` in `protocol Scanner`; you just happen to have chosen the same letter of the alphabet. This becomes clear if you rename:</div><div class=""><br class=""></div><div class="">```</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: rgb(186, 45, 162);" class="">func</span><span style="font-variant-ligatures: no-common-ligatures;" class=""><span class="m_4681716977856857885Apple-converted-space"> </span>use<S:<span class="m_4681716977856857885Apple-converted-space"> </span></span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(79, 129, 135);" class="">Scanner</span><span style="font-variant-ligatures: no-common-ligatures;" class="">, U>(</span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(186, 45, 162);" class="">_</span><span style="font-variant-ligatures: no-common-ligatures;" class=""><span class="m_4681716977856857885Apple-converted-space"> </span>s:<span class="m_4681716977856857885Apple-converted-space"> </span></span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(79, 129, 135);" class="">S</span><span style="font-variant-ligatures: no-common-ligatures;" class="">,<span class="m_4681716977856857885Apple-converted-space"> </span></span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(186, 45, 162);" class="">_</span><span style="font-variant-ligatures: no-common-ligatures;" class=""><span class="m_4681716977856857885Apple-converted-space"> </span>t:<span class="m_4681716977856857885Apple-converted-space"> </span></span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(79, 129, 135);" class="">U</span><span style="font-variant-ligatures: no-common-ligatures;" class="">) -><span class="m_4681716977856857885Apple-converted-space"> </span></span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(79, 129, 135);" class="">U</span><span style="font-variant-ligatures: no-common-ligatures;" class=""><span class="m_4681716977856857885Apple-converted-space"> </span>{</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures;" class=""> <span class="m_4681716977856857885Apple-converted-space"> </span></span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(186, 45, 162);" class="">return</span><span style="font-variant-ligatures: no-common-ligatures;" class=""><span class="m_4681716977856857885Apple-converted-space"> </span>s.frobnicate(t).<wbr class="">await()</span></div><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 style="margin: 0px; font-size: 11px; line-height: normal; font-family: menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures;" class=""><br class=""></span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures;" class=""><b class="">// cannot invoke 'frobnicate' with an argument list of type '(U)'</b></span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: menlo;" class=""><b class="">// expected an argument list of type '(T)'</b><br class=""></div></div><div class="">```</div><div class=""><br class=""></div><div class="">However, this works:</div><div class=""><br class=""></div><div class="">```</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: rgb(186, 45, 162);" class="">func</span><span style="font-variant-ligatures: no-common-ligatures;" class=""><span class="m_4681716977856857885Apple-converted-space"> </span>use<S:<span class="m_4681716977856857885Apple-converted-space"> </span></span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(79, 129, 135);" class="">Scanner</span><span style="font-variant-ligatures: no-common-ligatures;" class="">, T>(</span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(186, 45, 162);" class="">_</span><span style="font-variant-ligatures: no-common-ligatures;" class=""><span class="m_4681716977856857885Apple-converted-space"> </span>s:<span class="m_4681716977856857885Apple-converted-space"> </span></span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(79, 129, 135);" class="">S</span><span style="font-variant-ligatures: no-common-ligatures;" class="">,<span class="m_4681716977856857885Apple-converted-space"> </span></span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(186, 45, 162);" class="">_</span><span style="font-variant-ligatures: no-common-ligatures;" class=""><span class="m_4681716977856857885Apple-converted-space"> </span>t:<span class="m_4681716977856857885Apple-converted-space"> </span></span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(79, 129, 135);" class="">T</span><span style="font-variant-ligatures: no-common-ligatures;" class="">) -><span class="m_4681716977856857885Apple-converted-space"> </span></span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(79, 129, 135);" class="">T</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures;" class=""> <span class="m_4681716977856857885Apple-converted-space"> </span></span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(186, 45, 162);" class="">where</span><span style="font-variant-ligatures: no-common-ligatures;" class=""><span class="m_4681716977856857885Apple-converted-space"> </span></span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(79, 129, 135);" class="">S</span><span style="font-variant-ligatures: no-common-ligatures;" class="">.ScannerPromise.<wbr class="">Result ==<span class="m_4681716977856857885Apple-converted-space"> </span></span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(79, 129, 135);" class="">T</span><span style="font-variant-ligatures: no-common-ligatures;" class=""><span class="m_4681716977856857885Apple-converted-space"> </span>{</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: menlo; color: rgb(49, 89, 93);" class=""><span style="font-variant-ligatures: no-common-ligatures;" class=""> <span class="m_4681716977856857885Apple-converted-space"> </span></span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(186, 45, 162);" class="">return</span><span style="font-variant-ligatures: no-common-ligatures;" class=""><span class="m_4681716977856857885Apple-converted-space"> </span>s.</span><span style="font-variant-ligatures: no-common-ligatures;" class="">frobnicate</span><span style="font-variant-ligatures: no-common-ligatures;" class="">(t).</span><span style="font-variant-ligatures: no-common-ligatures;" class="">await</span><span style="font-variant-ligatures: no-common-ligatures;" class=""><wbr class="">()</span></div><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><div class=""><br class=""></div><div class="">...or just this:</div><div class=""><br class=""></div><div class="">```</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: rgb(186, 45, 162);" class="">func</span><span style="font-variant-ligatures: no-common-ligatures;" class=""><span class="m_4681716977856857885Apple-converted-space"> </span>use<S:<span class="m_4681716977856857885Apple-converted-space"> </span></span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(79, 129, 135);" class="">Scanner</span><span style="font-variant-ligatures: no-common-ligatures;" class="">>(</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: rgb(186, 45, 162);" class=""> <span class="Apple-converted-space"> </span>_</span><span style="font-variant-ligatures: no-common-ligatures;" class=""><span class="m_4681716977856857885Apple-converted-space"> </span>s:<span class="m_4681716977856857885Apple-converted-space"> </span></span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(79, 129, 135);" class="">S</span><span style="font-variant-ligatures: no-common-ligatures;" class="">,<span class="m_4681716977856857885Apple-converted-space"> </span></span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(186, 45, 162);" class="">_</span><span style="font-variant-ligatures: no-common-ligatures;" class=""><span class="m_4681716977856857885Apple-converted-space"> </span>t:<span class="m_4681716977856857885Apple-converted-space"> </span></span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(79, 129, 135);" class="">S</span><span style="font-variant-ligatures: no-common-ligatures;" class="">.ScannerPromise.<wbr class="">Result</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures;" class="">) -><span class="m_4681716977856857885Apple-converted-space"> </span></span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(79, 129, 135);" class="">S</span><span style="font-variant-ligatures: no-common-ligatures;" class="">.ScannerPromise.Result {</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: menlo; color: rgb(49, 89, 93);" class=""><span style="font-variant-ligatures: no-common-ligatures;" class=""> <span class="m_4681716977856857885Apple-converted-space"> </span></span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(186, 45, 162);" class="">return</span><span style="font-variant-ligatures: no-common-ligatures;" class=""><span class="m_4681716977856857885Apple-converted-space"> </span>s.</span><span style="font-variant-ligatures: no-common-ligatures;" class="">frobnicate</span><span style="font-variant-ligatures: no-common-ligatures;" class="">(t).</span><span style="font-variant-ligatures: no-common-ligatures;" class="">await</span><span style="font-variant-ligatures: no-common-ligatures;" class=""><wbr class="">()</span></div><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><div class=""><br class=""></div><blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left-width: 1px; border-left-style: solid; border-left-color: rgb(204, 204, 204); padding-left: 1ex;"><div style="word-wrap: break-word;" class=""><span class="m_4681716977856857885gmail-HOEnZb"><font color="#888888" class=""><div class=""></div><div class="">- Karl</div></font></span></div></blockquote></div></div></div></div></blockquote></div><br class=""></div></div><div class="">No, what you’ve done is something different. “frobnicate” is itself a generic function, so it should work if you rename the parameter to “U". You’ve just punted the constraint down the abstraction hierarchy.</div><div class=""><br class=""></div><div class="">This becomes clear if you try to continue working at the protocol-level:</div><div class=""><br class=""></div><blockquote style="margin: 0px 0px 0px 40px; border: none; padding: 0px;" class=""><div class=""><font face="Courier" class="">extension Scanner {</font></div><div class=""><font face="Courier" class=""><span class="m_4681716977856857885Apple-tab-span" style="white-space: pre-wrap;">        </span>func synchronised_frob<T>(_ t: T) -> T {</font></div><div class=""><font face="Courier" class=""><span class="m_4681716977856857885Apple-tab-span" style="white-space: pre-wrap;">        </span><span class="Apple-converted-space"> </span> return frobnicate(t).await()</font></div><div class=""><font face="Courier" class=""><span class="m_4681716977856857885Apple-tab-span" style="white-space: pre-wrap;">        </span>}</font></div><div class=""><font face="Courier" class="">}</font></div></blockquote><div class=""><br class=""></div><div class="">error: repl.swift:14:16: error: cannot invoke 'frobnicate' with an argument list of type '(T)'<br class=""> return frobnicate(t).await()<br class=""> ^<br class=""><br class="">repl.swift:14:16: note: expected an argument list of type '(T)'<br class=""> return frobnicate(t).await()<span class="HOEnZb"><font color="#888888" class=""><br class=""><br class=""></font></span></div></div></blockquote><div class=""><br class=""></div><div class="">Hmm, I'm not sure what you're trying to accomplish here. If I have an instance `s` that conforms to `Scanner`, then it must have a concrete associated type `ScannerPromise.Result`. `s.frobnicate()` can only take an argument of type `ScannerPromise.Result`; you want to pass an argument of arbitrary type `T` and have an existing instance conforming to `Scanner` retroactively change the type of `ScannerPromise.Result`?</div></div></div></div></div></blockquote></div><br class=""><div class="">Yes, but I may want ScannerPromise.Result to be a generic parameter. I refer you to my original email:</div><div class=""><br class=""></div><div class=""><div class=""></div><div class="">Even with SE-0142, this kind of constraint would not be possible. What I would like to write is something like this:</div><div class=""><br class=""></div><div class=""><div class=""><font face="Courier" class="">protocol Promise {</font></div><div class=""><font face="Courier" class=""> associatedtype Result</font></div><div class=""><font face="Courier" class=""> func await() -> Result</font></div><div class=""><font face="Courier" class="">}</font></div><div class=""><font face="Courier" class=""><br class=""></font></div><div class=""><font face="Courier" class="">protocol Scanner {</font></div><div class=""><font face="Courier" class=""> associatedtype ScanPromise<X>: Promise where Result == X // (incl. </font><span style="font-family: Courier;" class="">SE-0142)</span></div><div class=""><font face="Courier" class=""><br class=""></font></div><div class=""><font face="Courier" class=""> func promiseScan<T>(from: Offset, until: @escaping (Offset, Item) -> T?) -> ScanPromise<T?></font></div><div class=""><font face="Courier" class="">}</font></div></div><div class=""><div class=""><font face="Courier" class=""><br class=""></font></div><div class="">So, for example, I could write something like this (allowing my asynchronous Scanners to all automatically implement a synchronous API):</div><div class=""><font face="Courier" class=""><br class=""></font></div><div class=""><font face="Courier" class="">extension Scanner {</font></div><div class=""><font face="Courier" class=""> func scan(from f: Offset, until u: (Offset, Item) -> T?) -> T? {</font></div><div class=""><font face="Courier" class=""> return promiseScan(from: f, until: u).await()</font></div><div class=""><font face="Courier" class=""> }</font></div><div class=""><font face="Courier" class="">}</font></div></div></div><div class=""><br class=""></div><div class="">A conforming Promise would look like this:</div><div class=""><br class=""></div><div class=""><font face="Courier" class="">class MyPromise<Result>: Promise {</font></div><div class=""><font face="Courier" class=""> func await() -> Result { … }</font></div><div class=""><font face="Courier" class="">}</font></div><div class=""><br class=""></div><div class="">And a conforming scanner would look like this:</div><div class=""><br class=""></div><div class=""><font face="Courier" class="">class Scanner {</font></div><div class=""><font face="Courier" class=""> typealias ScanPromise<X> = MyPromise<X> // compiler checks where clause: Result == X</font></div><div class=""><font face="Courier" class=""><br class=""></font></div><div class=""><font face="Courier" class=""> public func promiseScan<T>(from f: Offset, until u: @escaping (Offset, Item) -> T?) -> MyPromise<T?> {</font></div><div class=""><font face="Courier" class=""> return MyPromise(from: f, until: u)</font></div><div class=""><font face="Courier" class=""> }</font></div><div class=""><font face="Courier" class="">}</font></div><div class=""><br class=""></div><div class="">- Karl</div></body></html>