I often find myself running up against errors like "Inheritance from 
non-protocol, non-class type”.

Here’s a contrived example.

public protocol NoiseMechanism : class {
    func makeNoise()
}

public protocol Animal {
    associatedtype NoiseMaker: NoiseMechanism
    
    static var numberOfLegs: Int { get }
}

open class AnimalWrapper<A: Animal> : A.NoiseMaker {
}


The benefit is that a consuming developer can inject types using one parameter 
and result in a robust type ecosystem.

This ties into my previous request to have non-class constraints (enums, 
structs) on protocols and in where clauses. I’m very interested in using 
protocols to enforce architectural decisions.

What do people generally think about this?  Is a protocol the right construct? 
Is this something that could be possible in the future, or completely off the 
table due to complexity, or just not addressed due to low priority?
_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution

Reply via email to