Problem 1 (5pts)

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 5

Problem 1 (5pts)

What derivation justify the following typing statement? (Please write


down the type derivation tree for the following typing)

f : B o o l →Bool ⊢ f ( i f f a l s e t h e n f(t r u e ) e l s e
f(f a l s e ) ) : Bool
Problem 2 (5pts)

Please write in OCAML, a type checker for the following simple


language with booleans:
Syntax of the Typed lambda-calculus with booleans

t ::= terms
x variable
Let x : T = t i n t Let

true constant true


false constant false
if t then t else t conditional

v ::= values

true true value


false false value
Types

T ::= types
Bool type of booleans
Typing rules

Γ ⊢t r u e : Bool (T-T r u e )
Γ ⊢f a l s e : Bool (T-Fa l se )

Γ ⊢t 1 : Bool Γ ⊢t 2 : T Γ ⊢t 3 : T
(T-If )
Γ ⊢i f t 1 t h e n t 2 e l s e t 3 : T

Γ, x:T 1 ⊢ t 2 : T2
(T-Abs)
Γ ⊢ let x:T1 in t 2 : T2

x:T ∈ Γ
(T-Va r )
Γ ⊢x : T

You might also like