Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
struct G<X> { }
protocol P {
associatedtype Arg
static func a(_ x: Arg)
}
extension G : P where X == Int {
typealias Arg = X
static func a(_ x: X) {
print("a")
}
}
// 推論できる
G.a(3)
func ga<X: P>(_ a: X.Arg, _ x: X.Type = X.self) {
x.a(a)
}
// 推論できない
ga(3)
// AppA.append(a, b) は ↓こう書き換えられる
// ↑のgaと同じカタチ
func append<X: HAppend>(_ a: X.Left, _ b: X.Right, _ x: X.Type = X.self) -> X.Result
{
return X.append(a, b)
}
let a: HCons<Int, HCons<String, HNil>> = HCons(1, HCons("string", HNil.hNil))
let b: HCons<Bool, HCons<Double, HNil>> = HCons(true, HCons(1.001, HNil.hNil))
let r = append(a, b)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.