[swift-evolution] StringInterpolationConvertible and StringLiteralConvertible inheritance

Ben Rimmington me at benrimmington.com
Mon May 16 00:49:17 CDT 2016


StringInterpolationConvertible inheritance of StringLiteralConvertible would
allow "static-string" and \(string-expression) segments to be differentiated.

/// For example, `"<p>\(paragraph)</p>" as HTML` would invoke:
///
/// HTML.init(stringInterpolation:
///     HTML.init(stringLiteral: "<p>"),
///     HTML.init(stringInterpolationSegment: paragraph),
///     HTML.init(stringLiteral: "</p>")
/// )
///
/// The conforming HTML type would be able to escape "<" and ">" characters
/// in the \(paragraph) string, without affecting the "<p>" and "</p>" tags.
///
protocol StringInterpolationConvertible : StringLiteralConvertible {
    init(stringInterpolation: Self...)
    init<T>(stringInterpolationSegment: T)
}

I also wonder why the following inheritance is needed:

* StringLiteralConvertible : ExtendedGraphemeClusterLiteralConvertible
* ExtendedGraphemeClusterLiteralConvertible : UnicodeScalarLiteralConvertible

-- Ben




More information about the swift-evolution mailing list