Opaque result types

A couple of ideas on this matter.

//#1 Tackling the syntax

// For in-place definition, implies that the opaque type can be named, and a 'when' keyword. 
-> opaque T where T: BidirectionalCollection,
                  T: RandomAccessCollection when Self: RandomAccessCollection,
                  T: MutableCollection when Self: MutableCollection,
                  T.Element == Element

// Through type aliases
typealias T = opaque BidirectionalCollection where 
                     T: RandomAccessCollection when Self: RandomAccessCollection,
                     T: MutableCollection when Self: MutableCollection,
                     T.Element == Element

// #2 Tackling verboseness

// If the compiler could infer a single return type and then auto-generate the necessary
// constraints for T, it's opaque version (the 'existential skeleton'),
// that would be fantastic. T.Element == Element is an example of an additional external constraint.
-> opaque T where T.Element == Element

What we really want is to be able to express merely the existence of a conditional conformance, right? I wouldn't say the current syntax for declaring conditional conformances is suitable for that, especially if we want to express a conditional conformance in a signature.

1 Like