Swift: Associated types cannot be related through tuples.
| Originator: | rix.rob | ||
| Number: | rdar://17499629 | Date Originated: | 29-Jun-2014 02:42 PM |
| Status: | Open | Resolved: | |
| Product: | Developer Tools | Product Version: | Xcode6-Beta2 (6A216f) |
| Classification: | Serious Bug | Reproducible: | Always |
Summary: A where clause cannot use tuples to relate type parameters to one another. Steps to Reproduce: Try to write one of the following functions: /// Returns a sequence containing the elements of the cartesian product of its elements. func cartesianProduct<A : Sequence, B : Sequence, C : Sequence where C.GeneratorType.Element == (A.GeneratorType.Element, B.GeneratorType.Element)> (a: A, b: B) -> C /// Returns a sequence consisting of the heads of the pairs. /// Note that it’s also unclear whether the _ is at all valid, but you could always represent it with an otherwise unused type parameter. func heads<A : Sequence, B : Sequence where A.GeneratorType.Element == (B.GeneratorType.Element, _)>(pairs: A) -> B /// Returns true if the pairs in `left` are flipped versions of the pairs in `right`. func flipped<A : Sequence, B : Sequence, T, U where A.GeneratorType.Element == (T, U), B == (U, T)>(left: A, right: B) -> Bool Expected Results: I expected these type signatures to be acceptable. Actual Results: The compiler complains that it expected an identifier for a type name. Regression: N/A Notes: Tuples are not first-class in the type system: you can’t extend them; you can’t typically construct 1-tuples; etc. Tuples are *incredibly* useful for defining ad hoc relationships between types (e.g. multiple returns), so it’s a shame that this isn’t taken further.
Comments
Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!