Skip to content

Instantly share code, notes, and snippets.

@a-voronov
Created September 6, 2017 23:34
Show Gist options
  • Save a-voronov/dc94febc8f047a670d1fd44b686d2e62 to your computer and use it in GitHub Desktop.
Save a-voronov/dc94febc8f047a670d1fd44b686d2e62 to your computer and use it in GitHub Desktop.
SKI Combinators in Swift 3
func s<A, B, C>(_ f: @escaping (A) -> (B) -> C) -> (@escaping (A) -> B) -> (A) -> C {
return { g in { x in f(x)(g(x)) } }
}
func k<A, B>(_ x: A) -> (B) -> A {
return { _ in x }
}
func i<A>(_ x: A) -> A {
return x
}
func i_<A>(_ x: A) -> A {
return k(x)(())
}
func i__<A>(_ x: A) -> A {
return s(k)(k(x))(x)
}
// - test -
i(42)
i_(42)
i__(42)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment