Skip to content

Instantly share code, notes, and snippets.

@CodaFi
Created July 31, 2014 06:52
Show Gist options
  • Save CodaFi/142e36054edfb688605c to your computer and use it in GitHub Desktop.
Save CodaFi/142e36054edfb688605c to your computer and use it in GitHub Desktop.
Sentential Combinators par Curry
// Playground - noun: a place where people can play
/// From Curry's doctoral thesis, Grundlagen der Kombinatorischen Logik, these combinators
/// have been largely abandoned due to the discovery of the SKI calculus (really just S and K).
/// Interestingly, Curry's system is derived from a number of popular axioms in propositional
/// logic. Namely:
///
/// B ≡ (B → C) → ((A → B) → (A → C))
/// C ≡ (A → (B → C)) → (B → (A → C))
/// K ≡ A → (B → A)
/// W ≡ (A → (A → B)) → (A → B)
///
/// Where function application stands for Modus Ponens.
/// Compose | Composes two functions.
func B<A, B, C>(f: A -> C) -> (B -> A) -> B -> C {
return { (g : (B -> A)) -> B -> C in
return { (x : B) -> C in
return f(g(x))
}
}
}
/// Swap | Swaps the arguments to a function.
func C<A, B, C>(f: (A -> B -> C)) -> B -> A -> C {
return { (x: B) -> A -> C in
return { (y: A) -> C in
return f(y)(x)
}
}
}
/// Discard | "Forgets" its second argument.
func K<A, B>(x : A) -> B -> A {
return { (y : B) -> A in
return x
}
}
/// Duplicate | Applies its second argument to a function twice.
func W<A, B>(f: (A -> A -> B)) -> A -> B {
return { (x : A) in
return f(x)(x)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment