[swift-evolution] Idea: Let Generic Parameters Have Labels & Default Values

Dave Abrahams dabrahams at apple.com
Sat Jan 23 16:52:59 CST 2016

on Sat Jan 23 2016, David Sweeris <swift-evolution at swift.org> wrote:

> The title seems fairly self-explanatory. Does anyone else think this could be useful?
> struct True : BooleanType {…} // Just part of the example… not in the proposal (although I do like it)
> struct False : BooleanType {…}  // Same
> // This is where the actual idea starts
> struct BigInt <BaseType: T = Int, CanEqualZero: U = Yes where T: IntegerArithmeticType, U: BooleanType> {…}
> The first parameter label could be skipped (or not), depending on
> whatever the rules for functions parameter labels ends up being
> (either way, they should be the same IMHO). Then variables could be
> declared like this:
> let foo =   BigInt()	    // BigInt<Int, No>()
> let bar =   BigInt<Int32>() // For when your data will be processed on a 32-bit platform or something
> let divisor = BigInt<CanEqualZero: False>()
> (The obvious follow-up suggestion is to then allow a generic type’s
> definition to change based on the results of logical operations
> performed purely on the types that are passed in, but I think that’s
> getting into “macro system” territory, and should probably be its own
> thing.)
> Anyway, thoughts?


More information about the swift-evolution mailing list