<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="">Hi Rudolf,<div class=""><br class=""></div><div class="">What you are describing is not possible right now. The protocol PointType cannot be used as a type at all, because it has an associated type requirement. Also it is not clear what a ‘where’ clause attached to a type alias would mean.</div><div class=""><br class=""></div><div class="">There has been some discussion of ‘generalized existentials’ on the evolution list. So eventually, you might be able to say something like this:</div><div class=""><br class=""></div><div class="">typealias Point = Any<Point : PointType where Point.Float == Float></div><div class=""><br class=""></div><div class="">Slava</div><div class=""><br class=""><div class=""><div><blockquote type="cite" class=""><div class="">On Sep 4, 2017, at 6:12 PM, Rudolf Adamkovič 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=""><meta http-equiv="Content-Type" content="text/html charset=utf-8" class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class="">I have the following <span style="font-family: Menlo; font-size: 14px; background-color: rgb(255, 255, 255);" class="">ProceduralDrawing</span> type:</div><div class=""><br class=""></div><div class=""><div style="margin: 0px; font-size: 14px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class=""><span style="color: #ba2da2" class="">public</span> <span style="color: #ba2da2" class="">struct</span> ProceduralDrawing<Float, Point: <span style="color: #4f8187" class="">PointType</span>> <span style="color: #ba2da2" class="">where</span> <span style="color: #4f8187" class="">Point</span>.<span style="color: #703daa" class="">Float</span> == <span style="color: #4f8187" class="">Float</span> {</div><div style="margin: 0px; font-size: 14px; line-height: normal; font-family: Menlo; color: rgb(0, 132, 0); background-color: rgb(255, 255, 255);" class=""><span style="" class=""> </span>// ... code that used Float and Point ...</div><div style="margin: 0px; font-size: 14px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class="">}</div></div><div class=""><br class=""></div><div class=""><div style="margin: 0px; font-size: 14px; line-height: normal; font-family: Menlo; color: rgb(186, 45, 162); background-color: rgb(255, 255, 255);" class="">public<span style="" class=""> </span>protocol<span style="" class=""> PointType {</span></div><div style="margin: 0px; font-size: 14px; line-height: normal; font-family: Menlo; color: rgb(186, 45, 162); background-color: rgb(255, 255, 255);" class=""><span style="" class=""> </span>associatedtype<span style="" class=""> Float: </span><span style="color: #703daa" class="">FloatingPoint</span></div><div style="margin: 0px; font-size: 14px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class=""> <span style="color: #ba2da2" class="">var</span> x: <span style="color: #703daa" class="">Float</span> { <span style="color: #ba2da2" class="">get</span> }</div><div style="margin: 0px; font-size: 14px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class=""> <span style="color: #ba2da2" class="">var</span> y: <span style="color: #703daa" class="">Float</span> { <span style="color: #ba2da2" class="">get</span> }</div><div style="margin: 0px; font-size: 14px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class="">}</div></div><div class=""><br class=""></div><div class="">I would like to avoid adding <span style="font-family: Menlo; font-size: 14px; background-color: rgb(255, 255, 255);" class="">Point</span> as a generic parameter but the following doesn’t work:</div><div class=""><span style="font-family: Menlo; font-size: 14px; background-color: rgb(255, 255, 255);" class=""><br class=""></span></div><div class=""><div style="margin: 0px; font-size: 14px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class=""><span style="color: rgb(186, 45, 162);" class="">public</span> <span style="color: rgb(186, 45, 162);" class="">struct</span> ProceduralDrawing<Float: <span style="color: rgb(112, 61, 170);" class="">FloatingPoint</span>> {</div><div style="margin: 0px; font-size: 14px; line-height: normal; font-family: Menlo; color: rgb(0, 132, 0); background-color: rgb(255, 255, 255);" class=""><span style="" class=""> </span>// ERROR: 'where' clause cannot be attached to a non-generic declaration</div><div style="margin: 0px; font-size: 14px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class=""> <span style="color: rgb(186, 45, 162);" class="">typealias</span> Point = <span style="color: rgb(79, 129, 135);" class="">PointType</span> <span style="color: rgb(186, 45, 162);" class="">where</span> Point.Float == Float</div><div style="margin: 0px; font-size: 14px; line-height: normal; font-family: Menlo; color: rgb(0, 132, 0); background-color: rgb(255, 255, 255);" class=""><span style="" class=""> </span>// ... code that uses Float and Point ...</div><div style="margin: 0px; font-size: 14px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class="">}</div></div><div class=""><br class=""></div><div class="">Is there a way to do this? If not, why?</div><div class=""><br class=""></div><div class="">Thanks!</div><div class=""><br class=""></div><div class="">R+</div></div>_______________________________________________<br class="">swift-users mailing list<br class=""><a href="mailto:swift-users@swift.org" class="">swift-users@swift.org</a><br class="">https://lists.swift.org/mailman/listinfo/swift-users<br class=""></div></blockquote></div><br class=""></div></div></body></html>