Skip to content

Instantly share code, notes, and snippets.

@mdiep
Created August 3, 2018 01:24
Show Gist options
  • Save mdiep/b4481a38a4b5ec48ec7ba8fb9e3ad229 to your computer and use it in GitHub Desktop.
Save mdiep/b4481a38a4b5ec48ec7ba8fb9e3ad229 to your computer and use it in GitHub Desktop.
Swift Tuple Wat
struct S<Args, Return> {}
infix operator ~
func ~ <A, T>(lhs: (A) -> T, rhs: String) -> S<(A), T> {
return S()
}
func ~ <A, B, T>(lhs: (A, B) -> T, rhs: String) -> S<(A, B), T> {
return S()
}
func f(_: Int, _: Int) -> Int { return 0 }
// Swift can't tell which `~` to use. That makes some sense.
_ = f ~ ""
// But this is also ambiguous:
let _: S<(Int, Int), Int> = f ~ ""
// However, more than one set of parens will disambiguate:
let _: S<((((Int, Int)))), Int> = f ~ ""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment