<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 May 2, 2017, at 4:39 PM, Nevin Brackett-Rozinsky via swift-users <<a href="mailto:swift-users@swift.org" class="">swift-users@swift.org</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class=""><div class="">If I write a generic function like this:</div><div class=""><br class=""></div><div class=""><font face="monospace, monospace" class="">func f<T>(_ x: T) { print("Generic: \(x)") }</font></div><div class=""><br class=""></div><div class="">I can pass it to another function like this:</div><div class=""><br class=""></div><div class=""><font face="monospace, monospace" class="">func g(_ fn: (Int) -> Void) { fn(0) }</font></div><div class=""><font face="monospace, monospace" class="">g(f) // Prints “Generic: 0”</font></div><div class=""><br class=""></div><div class="">However if I *also* write a non-generic function like this:</div><div class=""><br class=""></div><div class=""><font face="monospace, monospace" class="">func f(_ x: Int) { print("Int: \(x)") }</font><br class=""></div><div class=""><br class=""></div><div class="">Then when I make the same call as before:</div><div class=""><br class=""></div><div class=""><font face="monospace, monospace" class="">g(f) // Prints “Int: 0”</font></div><div class=""><br class=""></div><div class="">It passes in the new, non-generic version.</div><div class=""><br class=""></div><div class="">Is there something I can do, with both versions of f defined, to pass the generic f into g?</div></div></div></blockquote><br class=""></div><div>Not that I know of. Once the code path gets to g(), the compiler knows that the function is specifically an (Int)->Void, as opposed to the generic (T)->Void, and it’ll always go for the most specific overload. AFAIK, anyway.</div><div><br class=""></div><div>- Dave Sweeris</div></body></html>