Swift: Define type aliases among type constraints

Originator:rix.rob
Number:rdar://17893483 Date Originated:02-Aug-2014 12:06 AM
Status:Open Resolved:
Product:Developer Tools Product Version:Xcode6-Beta4 (6A267n)
Classification:Enhancement Reproducible:Not Applicable
 
Summary:
It would be extremely convenient to be able to define type aliases in the type parameters/constraints list.

For example, I’m implementing a polynomial algebra and I have the following definition for multiplication:

func * <Constant : Ring, Variable> (x: Term<Constant, Variable>, y: Term<Constant, Variable>) -> Term<Constant, Variable> {
	return Term(multiplication: x, y)
}

I’m having to repeat Term<Constant, Variable> quite a lot. It would be really nice to be able to define an alias:

func * <Constant : Ring, Variable, typealias Expression = Term<Constant, Variable>> (x: Expression, y: Expression) -> Expression {
	return Term(multiplication: x, y)
}

An alternative syntax would be to allow = to define an alias in a constraint:

func * <Constant : Ring, Variable, Expression where Expression = Term<Constant, Variable>> (x: Expression, y: Expression) -> Expression

Or just use ==, and make non-generic type constraints define typealiases instead of throwing errors.


Steps to Reproduce:
N/A

Expected Results:
N/A

Actual Results:
N/A

Regression:
N/A

Notes:
N/A

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!