Zulip Chat Archive

Stream: new members

Topic: free type variables in λ2 terms


rzeta0 (Jul 23 2025 at 01:23):

I'm working my way through Type Theory and Formal Proof, based in a recommendation here some months ago because I wanted to under how proof assistants like Lean work.

I'm stuck on the last exercise of Chapter 3 (second order lambda calculus). I'd welcome feedback on my attempted solution.


Exercise 3.21

Give a recursive definition for FTV(A)FTV(A), the set of free type variables in AA, for an expression AA in T2\mathbb{T}2 or in ΛT2Λ_{\mathbb{T}2}.

Let's remind ourselves of the recursive definition for free variables in untyped λ-terms.

Definition 1.4.1 (FVFV, the set of free variables of a λ-term)

(1) (Variable) FV(x)={x}FV(x) = \{x\}

(2) (Application) FV(MN)=FV(M)FV(N)FV(MN) = FV(M)∪FV(N)

(3) (Abstraction) FV(λx.M)=FV(M){x}FV(λx. M) = FV(M) \{x\}

Let's also remind ourselves of the sets T2\mathbb{T}2 and ΛT2Λ_{\mathbb{T}2}.

T2=V(T2T2)(ΠV:.T2)\mathbb{T}2 = \mathbb{V} |(\mathbb{T}2 →\mathbb{T}2) |(Π\mathbb{V} : ∗. \mathbb{T}2)

ΛT2=V(ΛT2ΛT2)(ΛT2T2)(λV:T2.ΛT2)(λV:.ΛT2)Λ_{\mathbb{T}2} = V|(Λ_{\mathbb{T}2}Λ_{\mathbb{T}2})|(Λ_{\mathbb{T}2}\mathbb{T}2)|(λV : \mathbb{T}2. Λ_{\mathbb{T}2})|(λ\mathbb{V} : ∗. Λ_{\mathbb{T}2})

Our recursive definition will need to cover all these cases. In the following section we'll consider each case, before rationalising the final definition.


AA in T2\mathbb{T}2, the λ2 Types

Let's consider the syntax cases for λ2 types.

V\mathbb{V}. These are type variables, for which we usually use lower case greek symbols, eg α,β,γα, β, γ. In this case the type variable is free, and so $$$$FTV(α)=\{α\}$$$$
(T2T2)(\mathbb{T}2 →\mathbb{T}2). These are arrow types between other type variables, for example αβα→β. In this case the free type variables are those in the "from" and "to" expressions. So $$$$FTV(M→N)=FTV(M) \cup FTV(N)$$$$
(ΠV:.T2)(Π\mathbb{V} : ∗. \mathbb{T}2). These are the abstractions over a single type variable. An example is Πα:.αMαΠα:*.α→Mα. In this case, the abstracted variable is bound, not free, and so $$$$FTV(Πα:*.M) = FTV(M) \setminus \{α\}$$$$

AA in ΛT2Λ_{\mathbb{T}2}, the Pre-Typed λ2 Terms

Let's now consider the syntax cases for the pre-typed λ2-terms.

VV. This is the simple case of a single term variable annotated with a type, eg xx. These variables are pre-typed, and so the expression xx has no type variables in it. This means $$$$FTV(x)=\emptyset$$$$
(ΛT2ΛT2)(Λ_{\mathbb{T}2}Λ_{\mathbb{T}2}). This is the application of one term to another, for example MNMN. Here we have $$$$FTV(MN)=FTV(M) \cup FTV(N)$$$$
(ΛT2T2)(Λ_{\mathbb{T}2}\mathbb{T}2). This is the application of a term to a type, for example Mα. In this case αα is free, and so we have $$$$FTV(Mα)=FTV(M) \cup \{α\}$$$$
(λV:T2.ΛT2)(λV : \mathbb{T}2. Λ_{\mathbb{T}2}). This is an abstraction over a term variable, for example λx.Mλx.M. Since xx is not a type variable, we have $$$$FTV(λx.M)=FTV(M)$$$$
(λV:.ΛT2)(λ\mathbb{V} : ∗. Λ_{\mathbb{T}2}). This is an abstraction over a type variable, for example λα.Mλα.M. Here αα is not free, and so $$$$FTV(λα.M) = FTV(M) \setminus \{α\}$$$$


My Attempt At A Recursive Definition

Consolidating the above observations we have

(Type Variable) FTV(α)={α}FTV(α)=\{α\}
(Term Variable) FTV(x)=FTV(x)=\emptyset
(Arrow Type) FTV(MN)=FTV(M)FTV(N)FTV(M→N)=FTV(M) \cup FTV(N)
(Application) FTV(MN)=FTV(M)FTV(N)FTV(MN)=FTV(M) \cup FTV(N)
(Abstraction) FTV(λα.N)=FTV(N){α}FTV(λα.N) = FTV(N) \setminus \{α\}
(Abstraction) FTV(Πα:.M)=FTV(M){α}FTV(Πα:*.M) = FTV(M) \setminus \{α\}

rzeta0 (Jul 23 2025 at 01:25):

Apologies in advance if the above is a little muddled. I'm self-teaching with no degree in maths / cs.

rzeta0 (Jul 23 2025 at 01:42):

(deleted)

rzeta0 (Jul 23 2025 at 15:50):

I've updated mu original question with my latest attempt at a solution, after some sleep and a walk.


Last updated: Dec 20 2025 at 21:32 UTC