[swift-evolution] Proposal: 'T(literal)' should construct T using the appropriate literal protocol if possible

Brent Royal-Gordon brent at architechies.com
Fri Jun 3 16:05:12 CDT 2016


> I am not the only one who feels that way.  Quoting Brent:
> 
> "But if you're going to call `init(integerLiteral:)` like it's `init(_:)`, I don't think that's a good idea. Parameter labels are supposed to be significant; we don't want to lose that.”
> 
> I agree with this.  That is the motivation for my suggestion.  I think it’s at least worth discussing as an alternative to magically allowing an external parameter label to be omitted.  Brent, what do you think of my suggestion?

I think it could be simpler:

	public struct Literal<LiteralType> {
		public let value: LiteralType
		internal init(_value value: LiteralType)
	}
	
	public protocol IntegerLiteralConvertible {
		associatedtype IntegerLiteralType
		init(_ literal: Literal<IntegerLiteralType>)
	}

Only the standard library can create a Literal, which it would do by constructing the IntegerLiteralType with its magic builtin literal stuff and wrapping it. You still have your magic parameter aspect, but without any actual magic, just access control. 

-- 
Brent Royal-Gordon
Architechies



More information about the swift-evolution mailing list