Closures and universal quantification
I've been trying to work out how to implement Church-encoded data types in Scala. It seems that it requires rank-n types since you would need a first-class const function of type forAll a. a -> (forAll b. b -> b) . However, I was able to encode pairs thusly: import scalaz._ trait Compose[F[_],G[_]] { type Apply = F[G[A]] } trait Closure[F[_],G[_]] { def apply[B](f: F[B]): G[B] } def pair[A,B](a: A, b: B) = new Closure[Compose[({type f[x] = A => x})#f, ({type f[x] = B => x})#f]#Apply, Id] { def apply[C](f: A => B => C) = f(a)(b) } For lists, I was able to encode cons : def cons[A](x: A) = {