Dependently Typed Binary Lambda Calculus

Dependently Typed Binary Lambda Calculus is a modification of Binary Lambda Calculus which adds type dependency, as well as features useful for code reuse.

Language overview
Every program in the language is made up of a single string of binary digits. There are four key patterns.

Application is ordinary function application, and expects two arguments. is used both for lambda abstractions and pi types. As a consequence, it expects two arguments, the first being the input type, and the second either being the output program or type, depending on whether it's being used as a lambda abstraction or a pi type. Numbers are precisely a count of the number of 1s in an expression. For example  is 1,   is 3, etc. expects to be followed by a number. That number then signifies a "line" in the program. Because of how this operator is encoded, it can be followed directly by, in which case it signifies the type of types.

Expressions in the language are tokenized left-to-right, then a syntax tree is built up right-to-left using a stack parser. A typical program will end with a stack that has several expressions in it. Each expression in the final stack is considered independent, as a proxy for a new line. For example  will be tokenized into something along the lines of , which is then parsed into four "lines", purely by virtue of the parser not being able to interpret it as a single tree.

in those expressions, the numbers that don't correspond to a line number are de Bruijn indices.

A correct program should consist of a sequence of pairs of expressions, corresponding to type-term pairs. In the previous example, the first pair is  and , representing a program of type  , the type of types. So that first line defines a new type (in this case, the church encoded unit type) and stores it in the first "line". The second pair is  and , signifying a program of type (whatever's on line 1). Since the unit type is on line 1, this second pair defines a term of the unit type.

Running a program primarily involves type checking. If a program successfully checks, then the normal form of the final term in the program is outputted.

Example: Lists
The list type will be a function from types to types;

defined as;

In this example,  is used both as a pi type and lambda expression, but its usage is disambiguated by the provided type.

We can proceed to define the nil list. Its type signifies that we're taking a type and making a list of that type.

The nil list is then implemented as

Cons becomes;

and concatenation becomes;

So, our full list implementation is;

0100110011001001100100110010100100101110010111011110111001001100001110100100110010011001010010010111001011101111011001001100101001000011101100001110111001001100101001000011101100100110010100100101111100101110111100000101111100000001111011101101001001100100001110100100001110110000111011100100110010000111010010000111011001001100101001001011111001011101111000000011111011100000001111011101101010

Example: 1 + 1 = 2
We start by defining the church encoded natural numbers on line 1.

We then define 1 and 2 for later on lines 2 and 3;

We define addition on line 4;

For reasoning about equality, we can define the ordinary Leibniz equality on line 5;

We can then define proof by reflexivity on line 6;

And we are finally ready for our conclusion, that 1 + 1 = 2,

Our complete proof is then;

0110010011001010010010110111011100111001001100101001001011011100010110011100100110010100100101101110001000101100100111001001110011100100111001001110010011001010010010110111000000011111011100000001111011101101010010011001010010110011001001100101001011001001011100110010001011100011011100100110010100000000111111101101010010011001010010010110011001000101101000000001111111001110000001111110011110011110011111000000111111110011100111110