Pitch: Protocols with private fields

Sure. I just wonder if the same thing might not be accomplished by composing public protocols, but using one private or internal conformance. What I have in mind is,

// Module A
public protocol X { ... }
public protocol EasyXImpl {}

extension X where Self: EasyXImpl {
  // implementations of X requirements in terms of EasyXImpl requirements
}

// Module B
import A
public struct Y: X private EasyXImpl {
  // EasyXImpl requirements
}

That would have a few advantages:

  1. The protocol system would retain its simplicity
  2. A protocol would have a single, well-understood meaning that doesn't change across access levels
  3. We'd avoid adding another language feature, since I believe we need scoped conformances anyway.
  4. You'd still have the option to create X conformance without EasyXImpl. In fact there might be several EasyXImpl variants for different means of achieving that conformance.
1 Like