[swift-users] Syntax for extending a struct conforming to a protocol with constraint

褚晓敏 mirrorinf at icloud.com
Sun Jul 10 00:54:32 CDT 2016

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)

``` swift
struct Polynomial<Field: Number> {
	//definition goes here

extension Polynomial: CustomStringConvertible where Field: CustomStringConvertible {
	//implementation goes here

Then I receive an error message from the compiler:
Extension of type 'Polynomial' with constraints cannot have an inheritance clause

This is the only way I know to do this(theoretically), but unfortunately it doesn’t work.

So, how can I achieve this? What syntax should be employed?

More information about the swift-users mailing list