<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Fri, Dec 11, 2015 at 3:22 PM, Drew Crawford via swift-evolution <span dir="ltr"><<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>></span> wrote: <blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word"><blockquote style="margin:0 0 0 40px;border:none;padding:0px"><div> func make() -> Any {</div></blockquote></div></blockquote><div><br></div><div>What about parameter types that you erase, would you downcast and trap in case of mismatch?</div><div><br></div><div>Did you look at AnySequence and other related types that implement a similar pattern manually?</div><div><br></div><div>How do you expect people will use the result of such an operation in practice? The type being 'Any' makes it completely opaque.</div><div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word"><div><div><div>Motivating case:</div><div><br></div><div>This proposal arises (most recently) from the problem of trying to write code that is generic across IPv4 and IPv6. For example</div><div><br></div></div><blockquote style="margin:0 0 0 40px;border:none;padding:0px"><div><div>final class Socket {</div></div><div><div> func getsockname() -> ???</div></div><div><div>}</div></div></blockquote><div><div><br></div><div>In the IPv4 case this function should return `sockaddr_in`, but in the v6 case it should return `sockaddr_in6`. So this socket can only be represented as a protocol with associated type requirements, and so it cannot be trivially used e.g. as a function parameter, as an ivar, etc. This significantly complicates the implementation.</div></div></div></div></blockquote><div><br></div><div>If your library is a high-level one, I definitely wouldn't want to see it return 'Any' from Socket methods. Instead, a library should erase the differences between transport mechanisms in the high-level API, while still providing a low-level API for those who need it, as well as for the implementation of the high-level API.</div><div> </div><div>Dmitri</div></div><div><br></div>-- <br><div class="gmail_signature">main(i,j){for(i=2;;i++){for(j=2;j<i;j++){if(!(i%j)){j=0;break;}}if<br>(j){printf("%d\n",i);}}} /*Dmitri Gribenko <<a href="mailto:gribozavr@gmail.com" target="_blank">gribozavr@gmail.com</a>>*/</div>
</div></div>