mirror of
https://github.com/apple/swift.git
synced 2026-10-12 14:50:47 +02:00
This is about a year's worth of changes, but mostly it just fixes various typos and cleans up the prose. I also split off the larger code examples into separate source files, to make them easier for people to play around with. There is some new content, but it is incomplete: - I started writing the 'Existential Types' chapter. - I started an overhaul of the 'Completion' chapter, including an example of the "decidable but non-FCRS generic signature", but I still need to think about how best to structure that proof. Since the new content is not done or very polished, I'm going to hold off on updating the PDF that is hosted on swift.org for now. I hope to finish this stuff off soon, though!
29 lines
500 B
Swift
29 lines
500 B
Swift
protocol Bar {
|
|
associatedtype Beer
|
|
func brew() -> Beer
|
|
}
|
|
|
|
protocol Pub {
|
|
associatedtype Beer
|
|
func pour() -> Beer
|
|
}
|
|
|
|
struct BrewPub<T> {}
|
|
|
|
extension BrewPub: Bar where T: Equatable {
|
|
typealias Beer = String
|
|
func brew() -> String { return "" }
|
|
}
|
|
|
|
extension BrewPub: Pub where T: Numeric {
|
|
typealias Beer = Float
|
|
func pour() -> Float { return 1.0 }
|
|
}
|
|
|
|
func both<T: Bar & Pub>(_ t: T) -> (T.Beer, T.Beer) {
|
|
return (t.brew(), t.pour())
|
|
}
|
|
|
|
let result = both(BrewPub<Int>())
|
|
print(result)
|