<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class=""><br class=""><div><br class=""><blockquote type="cite" class=""><div class="">On Nov 29, 2017, at 7:27 PM, Dave DeLong via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><meta http-equiv="Content-Type" content="text/html; charset=utf-8" class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class="">Hi SE,<div class=""><br class=""></div><div class="">I’m pondering some esoteric type stuff as I’m sketching out an improved date/time library (<a href="https://github.com/davedelong/Chronology" class="">https://github.com/davedelong/Chronology</a>), and I’m wondering two things:</div><div class=""><br class=""></div><div class="">1️⃣ Is there a way to express a type that does *not* conform to a protocol?&nbsp;</div><div class=""><br class=""></div><div class="">For example, let’s say I have three protocols:</div><div class=""><br class=""></div><div class=""><font face="Menlo" class=""><span style="font-size: 11px;" class="">protocol YearHaving { var year: Int }</span></font></div><div class=""><font face="Menlo" class=""><span style="font-size: 11px;" class="">protocol MonthHaving { var month: Int }</span></font></div><div class=""><font face="Menlo" class=""><span style="font-size: 11px;" class="">protocol DayHaving { var day: Int }</span></font></div><div class=""><font face="Menlo" class=""><span style="font-size: 11px;" class="">typealias DateHaving = YearHaving &amp; MonthHaving &amp; DayHaving</span></font></div><div class=""><br class=""></div><div class="">Now, I want to allow for some adjustments to values that have these types:</div><div class=""><br class=""></div><div class=""><font face="Menlo" class=""><span style="font-size: 11px;" class="">extension DayHaving {</span></font></div><div class=""><font face="Menlo" class=""><span style="font-size: 11px;" class="">&nbsp; &nbsp; func removingDay() → Self &amp;&nbsp;¬DayHaving // whatever type&nbsp;“self” is, except it does not conform to&nbsp;“DayHaving”, because you just removed the day value</span></font></div><div class=""><font face="Menlo" class=""><span style="font-size: 11px;" class="">}</span></font></div><div class=""><br class=""></div><div class="">Is this possible?</div></div></div></blockquote><div><br class=""></div>There is no way to express this.</div><div><br class=""><blockquote type="cite" class=""><div class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class=""><div class=""><br class=""></div><div class="">2️⃣ If this is not possible, would it be hard to add something like this in?</div></div></div></blockquote><br class=""></div><div>It would not be hard, although do note that it can only check “there is no conformance of the type to the protocol visible from this module”; a conformance might be present in some other module, or might be loaded dynamically later on. It can also be “hidden” from the static type system:</div><div><br class=""></div><div><font face="Menlo" class="">func f&lt;T&gt;(_: T) where&nbsp;<span style="font-size: 11px;" class="">¬DayHaving { }</span></font></div><div><font face="Menlo" class="">struct X { }</font></div><div><font face="Menlo" class="">f(X()) // okay</font></div><div><font face="Menlo" class="">struct Y : DayHaving { }</font></div><div><font face="Menlo" class="">f(Y()) // error: Y conforms to DayHaving but shouldn’t</font></div><div><font face="Menlo" class=""><br class=""></font></div><div><div><font face="Menlo" class=""><span style="font-size: 11px;" class="">func g&lt;T&gt;(_ t: T) { f(t) } // succeeds,&nbsp;because T is not known to conform to DayHaving</span></font></div><div class=""><font face="Menlo" class=""><span style="font-size: 11px;" class="">g(X()) // okay, as expected</span></font></div><div class=""><font face="Menlo" class=""><span style="font-size: 11px;" class="">g(Y()) // okay, but surprising</span></font></div><div class=""><font face="Menlo" class=""><span style="font-size: 11px;" class=""><br class=""></span></font></div></div><div><span class="Apple-tab-span" style="white-space:pre">        </span>- Doug</div><div><br class=""></div><br class=""></body></html>