<div dir="ltr"><div class="gmail_default" style="font-family:georgia,serif"><span style="font-family:arial,sans-serif;font-size:13px">How about this?</span></div><div class="gmail_default" style="font-family:georgia,serif"><br style="font-family:arial,sans-serif;font-size:13px"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><span style="font-family:arial,sans-serif;font-size:13px">struct Polynomial&lt;Field: Number, </span><span style="font-size:13px;font-family:arial,sans-serif">CustomStringConvertible </span><span style="font-family:arial,sans-serif;font-size:13px">&gt; {<br></span><span style="font-family:arial,sans-serif;font-size:13px">        //definition goes here<br></span><span style="font-family:arial,sans-serif;font-size:13px">}</span><br style="font-family:arial,sans-serif;font-size:13px"><span style="font-family:arial,sans-serif;font-size:13px">extension Polynomial: CustomStringConvertible {<br></span><span style="font-family:arial,sans-serif;font-size:13px">        //implementation goes here<br></span><span style="font-family:arial,sans-serif;font-size:13px">}</span></blockquote></div><div class="gmail_default" style="font-family:georgia,serif"><span style="font-family:arial,sans-serif;font-size:13px"><br></span></div><div class="gmail_default" style="font-family:georgia,serif"><br></div><div class="gmail_default" style="font-family:georgia,serif"><span style="font-family:arial,sans-serif;font-size:13px">Zhaoxin</span></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Sun, Jul 10, 2016 at 1:54 PM, 褚晓敏 via swift-users <span dir="ltr">&lt;<a href="mailto:swift-users@swift.org" target="_blank">swift-users@swift.org</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hello, every one. I want to extend a struct to conform to a protocol, while it’s itself a generic and needs a constraint. So I wrote this: (Swift 3)<br>
<br>
``` swift<br>
struct Polynomial&lt;Field: Number&gt; {<br>
        //definition goes here<br>
}<br>
<br>
extension Polynomial: CustomStringConvertible where Field: CustomStringConvertible {<br>
        //implementation goes here<br>
}<br>
```<br>
<br>
Then I receive an error message from the compiler:<br>
Extension of type &#39;Polynomial&#39; with constraints cannot have an inheritance clause<br>
<br>
This is the only way I know to do this(theoretically), but unfortunately it doesn’t work.<br>
<br>
So, how can I achieve this? What syntax should be employed?<br>
_______________________________________________<br>
swift-users mailing list<br>
<a href="mailto:swift-users@swift.org">swift-users@swift.org</a><br>
<a href="https://lists.swift.org/mailman/listinfo/swift-users" rel="noreferrer" target="_blank">https://lists.swift.org/mailman/listinfo/swift-users</a><br>
</blockquote></div><br></div>