<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="">You’re asking for GADTs: <a href="https://en.wikipedia.org/wiki/Generalized_algebraic_data_type" class="">https://en.wikipedia.org/wiki/Generalized_algebraic_data_type</a><div class=""><br class=""></div><div class="">This feature is difficult to implement correctly and efficiently and I doubt Swift will ever support it, but you never know…</div><div class=""><br class=""></div><div class="">Slava</div><div class=""><br class=""></div><div class=""><div><blockquote type="cite" class=""><div class="">On Mar 14, 2017, at 12:44 PM, Rex Fenley 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" class="">I've run into a problem recently when using generics with enums where I'm required to specify the type for a generic that isn't used for the enum case that's constructed.<div class=""><br class=""></div><div class="">Example:</div><div class=""><br class=""></div><div class="">
<font face="arial, helvetica, sans-serif" class="">protocol Mapping {<br class=""> associatedtype Destination<br class="">}<br class=""><br class="">enum EvictionPolicy {<br class=""> case append<br class=""> case replace<br class="">}<br class=""><br class="">enum Map<T: Mapping, U: Mapping> where U.Destination: Collection {<br class=""> case object(T)<br class=""> case collection(U, EvictionPolicy)<br class="">}<br class=""><br class="">class IntMapping: Mapping {<br class=""> typealias Destination = Int<br class="">}<br class=""><br class="">class IntsMapping: Mapping {<br class=""> typealias Destination = [Int]<br class="">}<br class=""><br class="">// Must specify types for generics that are not in use<br class="">let o = Map<IntMapping, IntsMapping>.object(IntMapping())<br class="">let c = Map<IntMapping, IntsMapping>.collection(IntsMapping(), EvictionPolicy.append)<br class=""><br class="">What I'd like to be able to do is the following<br class=""><br class="">enum Map<T: Mapping> {<br class=""> case object(T)<br class=""> case collection(T, EvictionPolicy) where T.Destination: Collection<br class="">}</font></div><div class=""><font face="arial, helvetica, sans-serif" class=""><br class=""></font></div><div class=""><font face="arial, helvetica, sans-serif" class="">Could this be added to the language?<br class=""></font><div class=""><br class=""></div>-- <br class=""><div class="gmail_signature"><div dir="ltr" class=""><span class=""><div style="line-height: 1.15; margin-top: 0pt; margin-bottom: 0pt;" class=""><span style="font-size:16px;font-family:arial;background-color:transparent;font-style:italic;vertical-align:baseline;white-space:pre-wrap" class="">Rex Fenley</span><span style="font-size:16px;font-family:arial;background-color:transparent;vertical-align:baseline;white-space:pre-wrap" class=""> </span><span style="font-size:11px;font-family:arial;color:rgb(153,153,153);background-color:transparent;vertical-align:baseline;white-space:pre-wrap" class="">|</span><span style="line-height:1.15;font-family:arial;color:rgb(153,153,153);background-color:transparent;vertical-align:baseline;white-space:pre-wrap" class=""> </span><span style="font-size:11px;font-family:arial;color:rgb(153,153,153);background-color:transparent;vertical-align:baseline;white-space:pre-wrap" class="">IOS DEVELOPER</span><br class=""></div></span><span class=""><br class=""><div style="line-height: 1.15; margin-top: 0pt; margin-bottom: 0pt;" class=""><span style="font-size:11px;font-family:arial;color:rgb(153,153,153);vertical-align:baseline;white-space:pre-wrap;background-color:transparent" class=""><img src="https://lh5.googleusercontent.com/xMgzw3JkFL3DLkdwyq0WxJzKs_XP57gVVCaBMvgi1FKCjSeue0xdx3JZeCWBlxN4KRHhHOfdvJbc1N-AjTwXcKIq4cjJg9H7iaFpQ8WbO4N3c9Y5dzi19cPOs_owPquuqw" width="250px;" height="53px;" style="border: none;" class=""></span></div><div style="line-height: 1.15; margin-top: 0pt; margin-bottom: 0pt;" class=""><a href="https://www.remind.com/" style="text-decoration:none" target="_blank" class=""><span style="font-size:11px;font-family:arial;color:rgb(17,85,204);font-weight:bold;text-decoration:underline;vertical-align:baseline;white-space:pre-wrap;background-color:transparent" class="">Remind.com</span></a><span style="font-family:arial;vertical-align:baseline;white-space:pre-wrap;background-color:transparent" class=""> </span><span style="font-size:11px;font-family:arial;vertical-align:baseline;white-space:pre-wrap;background-color:transparent" class="">| </span><a href="http://blog.remind.com/" style="text-decoration:none" target="_blank" class=""><span style="font-size:11px;font-family:arial;color:rgb(17,85,204);text-decoration:underline;vertical-align:baseline;white-space:pre-wrap;background-color:transparent" class="">BLOG</span></a><span style="font-size:11px;font-family:arial;vertical-align:baseline;white-space:pre-wrap;background-color:transparent" class=""> | </span><a href="https://twitter.com/remindhq" style="text-decoration:none" target="_blank" class=""><span style="font-size:11px;font-family:arial;color:rgb(17,85,204);text-decoration:underline;vertical-align:baseline;white-space:pre-wrap;background-color:transparent" class="">FOLLOW US</span></a><span style="font-size:11px;font-family:arial;vertical-align:baseline;white-space:pre-wrap;background-color:transparent" class=""> | </span><span style="font-family:arial;vertical-align:baseline;white-space:pre-wrap;background-color:transparent" class=""> </span><span style="text-decoration:underline;font-size:11px;font-family:arial;color:rgb(17,85,204);vertical-align:baseline;white-space:pre-wrap;background-color:transparent" class=""><a href="https://www.facebook.com/remindhq" style="text-decoration:none" target="_blank" class="">LIKE US</a></span></div></span></div></div>
</div></div>
_______________________________________________<br class="">swift-evolution mailing list<br class=""><a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a><br class="">https://lists.swift.org/mailman/listinfo/swift-evolution<br class=""></div></blockquote></div><br class=""></div></body></html>