Rules for Type Derivations - Programming Languages and Compilers | CS 421, Study notes of Computer Science

Material Type: Notes; Class: Progrmg Languages & Compilers; Subject: Computer Science; University: University of Illinois - Urbana-Champaign; Term: Fall 2006;

Typology: Study notes

Pre 2010

Uploaded on 03/11/2009

koofers-user-8ud
koofers-user-8ud 🇺🇸

8 documents

1 / 1

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
1
CS 421 Midterm Name:______________________________
Rules for type derivations:
Constants:
________
Γ|- n : int (assuming n is an integer constant)
___________ ____________
Γ|- true : bool Γ|- false : bool
Variables:
_______
Γ |- x : σ if Γ(x) = σ
Primitive operators ( { +, -, *, …}):
Γ |- e1 : int Γ |- e2 : int
Γ |- e1 e2 : int
Relations ( ˜ { < , > , =, <=, >= }):
Γ |- e1 : int Γ |- e2 : int
Γ |- e1 ˜ e2 :bool
Connectives :
Γ |- e1 : bool Γ |- e2 : bool Γ |- e1 : bool Γ |- e2 : bool
Γ |- e1 && e2 : bool Γ |- e1 || e2 : bool
If_then_else rule:
Γ |- e1 : bool Γ |- e2 : τ Γ |- e3 : τ
Γ |- (if e1 then e2 else e3) : τ
Application rule: fun rule:
Γ |- e1 : τ1 τ2 Γ |- e2 : τ1 [x : τ1 ] + Γ |- e : τ2
Γ |- (e1 e2) : τ2Γ |- fun x -> e : τ1 τ2
let rule: let rec rule:
Γ |- e1 : τ1 [x : τ1 ] + Γ |- e2 : τ2[x: τ1 ] + Γ |- e1:τ1 [x: τ1 ] + Γ |- e2:τ2
Γ |- (let x = e1 in e2 ) : τ2 Γ |- (let rec x = e1 in e2 ) : τ2

Partial preview of the text

Download Rules for Type Derivations - Programming Languages and Compilers | CS 421 and more Study notes Computer Science in PDF only on Docsity!

1 CS 421 Midterm Name:______________________________ Rules for type derivations: Constants:


Γ|- n : int (assuming n is an integer constant)


Γ|- true : bool Γ|- false : bool Variables:


Γ |- x : σ if Γ(x) = σ Primitive operators ( ⊕ ∈ { +, -, *, …}): Γ |- e 1 : int Γ |- e 2 : int Γ |- e 1 ⊕ e 2 : int Relations ( (^) ˜ ∈ { < , > , =, <=, >= }): Γ |- e 1 : int Γ |- e 2 : int Γ |- e 1 ˜ e 2 :bool Connectives : Γ |- e 1 : bool Γ |- e 2 : bool Γ |- e 1 : bool Γ |- e 2 : bool Γ |- e 1 && e 2 : bool Γ |- e 1 || e 2 : bool If_then_else rule: Γ |- e 1 : bool Γ |- e 2 : τ Γ |- e 3 : τ Γ |- (if e 1 then e 2 else e 3 ) : τ Application rule: fun rule: Γ |- e 1 : τ 1 → τ 2 Γ |- e 2 : τ 1 [x : τ 1 ] + Γ |- e : τ 2 Γ |- (e 1 e 2 ) : τ 2 Γ |- fun x -> e : τ 1 → τ 2 let rule: let rec rule: Γ |- e 1 : τ 1 [x : τ 1 ] + Γ |- e 2 : τ 2 [x: τ 1 ] + Γ |- e 1 :τ 1 [x: τ 1 ] + Γ |- e 2 :τ 2 Γ |- (let x = e 1 in e 2 ) : τ 2 Γ |- (let rec x = e 1 in e 2 ) : τ 2