Skip to content

Instantly share code, notes, and snippets.

@tinybyte
tinybyte / SKI_Applicative.scala
Created August 9, 2012 07:46 — forked from tonymorris/SKI_Applicative.scala
Applicative Functor / SKI combinator calculus
object SKI_Applicative {
/*
First, let's talk about the SK combinator calculus and how it contributes to solving your problem.
The SK combinator calculus is made of two functions (aka combinators): S and K. It is sometimes called the SKI combinator calculus, however, the I combinator can be derived from S and K. The key observation of SK is that it is a turing-complete system and therefore, anything that can be expressed as SK is also turing-complete. Here is a demonstration that Scala's type system is turing-complete (and therefore, undecidable) for example[1].
The K combinator is the most trivial of the two. It is sometimes called "const" (as in Haskell). There is also some discussion about its evaluation strategy in Scala and how to best express it[2]. The K function might be paraphrased as, "takes a value and returns a (constant) unary function that always returns that value."
*/
def k[A, B]: A => B => A =
a => _ => a