<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"><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 15 Oct 2016, at 19:00, Karl Wagner wrote:</div></blockquote><blockquote type="cite" class=""><br class="Apple-interchange-newline"><div class=""><span style="font-family: Helvetica; font-size: 14px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">The edge-case I have in mind is... let's say we synthesised RawRep conformance for all Equatable raw-types. That would allow you use struct and class rawvalues with our shorthand syntax.</span><br style="font-family: Helvetica; font-size: 14px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""></div></blockquote></div><br class=""><div class="">I am not saying the compiler should do all the work. It’s OK with me if I have to make the rawValue type RawRepresentable myself.</div><div class=""><br class=""></div><div class=""><div class="">Consider the following code, where Rectangle is a type that is useful on its own:</div><div class=""><br class=""></div><div class="">import Cocoa</div><div class=""><br class=""></div><div class="">struct Rectangle: RawRepresentable</div><div class=""><span class="Apple-tab-span" style="white-space:pre">        </span>{</div><div class="">&nbsp; &nbsp; var width: Int = 0</div><div class="">&nbsp; &nbsp; var height: Int = 0</div><div class="">&nbsp;<span class="Apple-tab-span" style="white-space:pre">        </span>}</div><div class=""><br class=""></div><div class="">extension Rectangle: RawRepresentable</div><div class=""><span class="Apple-tab-span" style="white-space:pre">        </span>{</div><div class=""><span class="Apple-tab-span" style="white-space:pre">        </span>typealias RawValue = String</div><div class="">&nbsp; &nbsp;&nbsp;</div><div class="">&nbsp; &nbsp; init( rawValue:String )</div><div class=""><span class="Apple-tab-span" style="white-space:pre">        </span>{</div><div class="">&nbsp; &nbsp; &nbsp; &nbsp; let values = rawValue.componentsSeparatedByString("x")</div><div class="">&nbsp; &nbsp; &nbsp; &nbsp; if let width = Int(values[0]), let height = Int(values[1]) { self.init( width:width, height:height ) }</div><div class=""><span class="Apple-tab-span" style="white-space:pre">        </span>else { self.init( width:0, height:0 ) }</div><div class="">&nbsp; &nbsp; <span class="Apple-tab-span" style="white-space:pre">        </span>}</div><div class=""><span class="Apple-tab-span" style="white-space:pre">        </span></div><div class="">&nbsp; &nbsp; var rawValue:String { return "\(width)x\(height)" }</div><div class=""><span class="Apple-tab-span" style="white-space:pre">        </span>}</div><div class=""><br class=""></div><div class="">enum RectFormat: Rectangle</div><div class=""><span class="Apple-tab-span" style="white-space:pre">        </span>{</div><div class="">&nbsp; &nbsp; case SMALL = “30x30"</div><div class="">&nbsp; &nbsp; case MEDIUM = “60x60"</div><div class="">&nbsp; &nbsp; case LARGE = “120x120"</div><div class=""><br class=""></div><div class="">&nbsp; &nbsp; var width: Int { return rawValue.width }</div><div class="">&nbsp; &nbsp; var height: Int { return rawValue.height }</div><div class=""><span class="Apple-tab-span" style="white-space:pre">        </span>}</div><div class=""><br class=""></div><div class="">let fmt = RectFormat.MEDIUM</div><div class="">print ("width: \(fmt.width) height: \(fmt.height)")</div><div class=""><br class=""></div><div class="">This was written in Xcode and Swift 2.2 (I cannot yet update to Swift 3) and does not compile.</div><div class=""><br class=""></div><div class="">Given this Rectangle struct I would like to be able to write</div><div class=""><br class=""></div><div class="">enum RectFormat: Rectangle</div><div class=""><span class="Apple-tab-span" style="white-space:pre">        </span>{</div><div class="">&nbsp; &nbsp; case SMALL = Rectangle (30,30)</div><div class="">&nbsp; &nbsp; case MEDIUM = Rectangle (60,60)</div><div class="">&nbsp; &nbsp; case LARGE = Rectangle (120,120)</div><div class=""><span class="Apple-tab-span" style="white-space:pre">        </span>}</div><div class=""><br class=""></div><div class="">let fmt = RectFormat.MEDIUM</div><div class="">print ("width: \(fmt.width) height: \(fmt.height)”)</div><div class="">let fmt2 = RectFormat( rawValue:Rectangle (40,40) ) // fmt2 is nil</div><div class=""><br class=""></div><div class="">IOW no need for literals, no need to copy the properties or methods of Rectangle, omit rawValue when accessing them.</div><div class=""><br class=""></div><div class="">If the compiler needs to store the cases as literals we can require RawValue to be StringLiteralType, IntegerLiteralType or FloatLiteralType (or a tuple of these).</div><div class="">IMHO the developer can take on the responsibility for making sure the mapping from and to RawValue is one to one.</div><div class=""><br class=""></div><div class="">I am not sure if this is purely additive sugar (might be, except in case of tuples?).</div><div class=""><br class=""></div><div class="">Jan E.</div><div class=""><br class=""></div></div></body></html>