Created
March 22, 2019 04:32
-
-
Save omochi/56e11c857d73e0728ab7985de145e7a2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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