nprofile1qy2hwumn8ghj7un9d3shjtnddaehgu3wwp6kyqpqkyagcdfagmkfyqwplpv0neng7nq24p4q3l4v7jhe3srlsmntufzs8tcpun (nprofile…cpun) nprofile1qy2hwumn8ghj7un9d3shjtnddaehgu3wwp6kyqpq26zlh0z0afh055uppfrtzhkkr824ya2p9wa3a2ghhj8ntfpnm7xqtulpgt (nprofile…lpgt) It is hard to find links to such things, though I'm sure they exist in abundance, but perhaps it would be helpful for me to briefly explain the idea in tweet form.
You want to index your types in natural numbers that describe how many variables are in the context. First, we should give a type of variables that can be made in a context of length "n". This is the type of de bruijn indices:
inductive Ix : Nat → Type where
| top : Ix (n+1)
| pop : Ix n → Ix (n+1)
So "top" means the rightmost in the context, and "pop x" means the variable that comes before "x". So the second-to-rightmost variable is "pop top".
Next, we define *terms* where variables are given by de bruijn indices. This starts off like this:
inductive Tm : Nat -> Type where
| var : Ix n -> Tm n
| lam : Tm (n+1) -> Tm n
| app : Tm n -> Tm n -> Tm n
...and so on. So you see that when you bind a variable, you increase the length of the context.
So then the term "\x.\y. x" is written: lam (lam (pop top)).
Does this help?