SE-0244: Opaque Result Types

For an opaque typealias, you need to describe the type as seen from outside, as well as the underlying type. In full generality, there may be multiple structural parts of the type you want to hide, so you need what amounts to another generic signature to describe it:

opaque typealias PartitionedCollection<T: Collection>
  = <U: Collection, V: Collection> (oddValues: U, evenValues: V)
    where T.Element == U.Element, U.Element == V.Element

@orobio did a great job describing this in his "reverse generics" thread, which describes the problem in terms of opaque returns, though opaque typealiases are effectively the same thing as far as type system behavior. Phrasing something like this as two independent opaque typealiases would not be equivalent, because you would lose the ability to describe the constraints between the two elements of the tuple.

1 Like