Scala Typelevel Church Encodings
import sturch.nats._
import sturch.bools._
type x = Plus[`3`, `4`]
type y = Mult[`3`, `2`]
type `IsTypelevelProgrammingFun?` = Not[EQ[x, y]]
type result = If[`IsTypelevelProgrammingFun?`, Mult[x, y], Zero]
For fun of course.
This repository contains an attempt to encode some structures(e.g. booleans and natural numbers) using only types. You can findout more by googling "type lambdas" and "Church encoding".
This library is not published anywhere, because I see no point in using it. If thats a problem let me know and I will publish it to sonatype repository.
Inside you can find five packages:
sturch
- definition of type lambda, type-to-value-level parser and printer for type lambdassturch.bools
- encoding of booleanssturch.nats
- encoding of natural numberssturch.pairs
- encoding of pair data structure(2-sized tuples)sturch.lists
- encoding of list data structure
All of the encoding is based on the Type Lambda abstraction which is defined like this:
trait TL {
type Apply[T <: TL] <: TL
}
And some concrete functions can be encoded like this:
type Identity = TL {
type Apply[T <: TL] = T
}
To see more examples you can look into tests.