In “Types and Programming Languages”, section 6.1.2 they talk about a naming context used to number free variables in lambda expressions. Using the example scheme they’ve provided, both λx.xb and λx.xx will have their de Bruijn representation as λ.00 when they’re clearly different terms. How does this work?
In Types and Programming Languages, section 6.1.2 they talk about a naming context used
Share
As you mentioned the book uses a naming context which maps
nfree variables to the numbers from0ton-1. However if you look closely at the examples in the book, you’ll notice that it doesn’t use those numbers directly to represent the variables. For example it representsλw. y wasλ. 4 0even though the mapping foryis 3, not 4.What’s happening here is that he adds the nesting depth of the variable to the number. I.e. if a free variable
vis nested indlambdas, it gets the indexΓ(v)+d, not justΓ(v).So in your example using the context
Γ {b -> 0}λx.xbwould be represented asλ. 0 1, notλ. 0 0. Thus there’s no ambiguity.