Está en la página 1de 3

Características de Lenguajes de Programación

Primer parcial
Licenciatura en Informática • Universidad Nacional de Quilmes
12 de octubre de 2022

Nombre y apellido: PONER NOMBRE ACA

Introducción
En la práctica extendimos la gramática de PCF con pares (⟨t, r⟩) y los proyectores (π1 t y π2 t). Alternativamente, los
destructores pueden ser definidos como sigue:

δ 1 (t, x.s) y δ 2 (t, x.s)

con las siguientes reglas de reducción:

δ 1 (⟨t, r⟩, x.s) → s[t/x]


δ 2 (⟨t, r⟩, x.s) → s[r/x]

En este caso, π1 t es el caso particular δ 1 (t, x.x), ya que δ 1 (⟨t, r⟩, x.x) reduce a x[t/x] = t, y similarmente δ 2 (⟨t, r⟩, x.x)
reduce a r. A esto se lo conoce como eliminación generalizada.
Tip: En general, δ 1 (t, x.s) se comporta igual que (λx.s)π1 t.

Ejercicios
1. Dar las reglas de tipado (en tipos simples) para los nuevos constructores: ⟨t, r⟩, δ 1 (t, x.s) y δ 2 (t, x.s).
Tips:
a) Los tipos se extienden sólo con A ∧ B.
b) La variable x está ligada en δ 1 (t, x.s). Pensar en (λx.s)π1 t.

Solución:
Las reglas a agregar son las siguientes.

Γ⊢t:A Γ⊢r:B ∧ Γ ⊢ t : A ∧ B Γ, x : A ⊢ s : C Γ ⊢ t : A ∧ B Γ, x : B ⊢ s : C
i ∧e1 ∧e2
Γ ⊢ ⟨t, r⟩ : A ∧ B Γ ⊢ δ 1 (t, x.s) : C Γ ⊢ δ 2 (t, x.s) : C

2. Extender el algoritmo de Hindley para las nuevas reglas definidas en el punto 1.


Solución:
Las reglas a agregar son las siguientes.

Γ ⊢ t ⇝ A, τ Γ ⊢ r ⇝ B, σ Γ ⊢ t ⇝ A, τ Γ, x : B ⊢ s ⇝ C, σ Γ ⊢ t ⇝ A, τ Γ, x : B ⊢ s ⇝ C, σ
Γ ⊢ ⟨t, r⟩ ⇝ A ∧ B, τ ∪ σ Γ ⊢ δ 1 (t, x.s) ⇝ C, τ ∪ σ ∪ {A = B ∧ X} Γ ⊢ δ 2 (t, x.s) ⇝ C, τ ∪ σ ∪ {A = X ∧ B}

3. El algoritmo de Robinson se extiende de la siguiente manera:

Si una ecuación es de la forma A ∧ B = nat, nat = A ∧ B, A ∧ B = C ⇒ D o C ⇒ D = A ∧ B, responder


error.
Si una ecuación es de la forma A ∧ B = C ∧ D reemplazar por las ecuaciones A = C y B = D.

1
Derivar el tipo (utilizando Hindley, como fue extendido en el punto 2 y Robinson) al siguiente término
λx.δ 1 (x, y.y + 1)

Solución:
Hindley:
x : X, y : Y ⊢ y ⇝ Y, ∅ x : X, y : Y ⊢ 1 ⇝ nat, ∅
x : X ⊢ x ⇝ X, ∅ x : X, y : Y ⊢ y + 1 ⇝ nat, {Y = nat, nat = nat}
x : X ⊢ δ 1 (x, y.y + 1) ⇝ nat, {Y = nat, nat = nat, X = Y ∧ Z}
⊢ λx.δ 1 (x, y.y + 1) ⇝ X ⇒ nat, {Y = nat, nat = nat, X = Y ∧ Z}

Robinson:

 Y = nat  
Y = nat Y = nat
nat = nat =⇒ =⇒ =⇒ θ = [nat/Y, nat ∧ Z/X]
X =Y ∧Z X = nat ∧ Z
X =Y ∧Z

Tipo más general: nat ∧ Z ⇒ nat para cualquier Z.



4. Dar la traza de λx.δ 1 (x, y.λz.y + 1) ⟨2, (λw.w)3⟩ en CBV fuerte.
Solución:

λx.δ 1 (x, y.λz.y + 1) ⟨2, (λw.w)3⟩ → λx.δ 1 (x, y.λz.y + 1) ⟨2, 3⟩


 

→ δ 1 (⟨2, 3⟩, y.λz.y + 1)


→ λz.2 + 1
→ λz.3

5. Extender la relación Γ ⊢ t ,→ v de interpretación en CBV (ver Definición 7.6 del apunte) para el PCF con pares
con eliminación generalizada. Los valores en este caso son los siguientes:
v := n | [λx.t, Γ] | ⟨v, v⟩
donde [t, Γ] es la notación para thunks y cierres (para no confundirlos con la notación de pares).
Solución:
Las reglas a agregar son las siguientes:

Γ ⊢ t ,→ v Γ ⊢ t ,→ w Γ ⊢ t ,→ ⟨v1 , v2 ⟩ Γ, x = v1 ⊢ s ,→ w Γ ⊢ t ,→ ⟨v1 , v2 ⟩ Γ, x = v2 ⊢ s ,→ w
1
Γ ⊢ ⟨t, r⟩ ,→ ⟨v, w⟩ Γ ⊢ δ (t, x.s) ,→ w Γ ⊢ δ 2 (t, x.s) ,→ w

6. Dar un tipo para el siguiente término en cualquier sistema polimórfico de los vistos en clase (decir cuál se está
utilizando).
let i = λx.x in i(ii)

Solución:
Damos los tres (se pedía sólo uno).
Polimorfismo-let
axv axv
i : ∀X.[X ⇒ X] ⊢ i : ∀X.[X ⇒ X] i : ∀X.[X ⇒ X] ⊢ i : ∀X.[X ⇒ X]
axv axv ∀e ∀e
x : [X] ⊢ x : [X] i : ∀X.[X ⇒ X] ⊢ i : ∀X.[X ⇒ X] i : ∀X.[X ⇒ X] ⊢ i : [(X ⇒ X) ⇒ (X ⇒ X)] i : ∀X.[X ⇒ X] ⊢ i : [X ⇒ X]
⇒i ∀e ⇒e
⊢ λx.x : [X ⇒ X] i : ∀X.[X ⇒ X] ⊢ i : [(X ⇒ X) ⇒ (X ⇒ X)] i : ∀X.[X ⇒ X] ⊢ ii : [X ⇒ X]
∀i ⇒e
⊢ λx.x : ∀X.[X ⇒ X] i : ∀X.[X ⇒ X] ⊢ i(ii) : [X ⇒ X]
let
⊢ let i = λx.x in i(ii) : [X ⇒ X]
∀i
⊢ let i = λx.x in i(ii) : ∀X.[X ⇒ X]

Sistema F
axv axv
i : ∀X.X ⇒ X ⊢ i : ∀X.X ⇒ X
axv axv ∀e i : ∀X.X ⇒ X ⊢ i : ∀X.X ⇒ X ∀e
x : [X] ⊢ x : [X] i : ∀X.X ⇒ X ⊢ i : ∀X.X ⇒ X i : ∀X.X ⇒ X ⊢ i : (X ⇒ X) ⇒ (X ⇒ X) i : ∀X.X ⇒ X ⊢ i : X ⇒ X
⇒i ∀e ⇒e
⊢ λx.x : X ⇒ X i : ∀X.X ⇒ X ⊢ i : (X ⇒ X) ⇒ (X ⇒ X) i : ∀X.X ⇒ X ⊢ ii : X ⇒ X
∀ ⇒e
⊢ λx.x : ∀X.X ⇒ X i i : ∀X.X ⇒ X ⊢ i(ii) : X ⇒ X
let
⊢ let i = λx.x in i(ii) : X ⇒ X
∀i
⊢ let i = λx.x in i(ii) : ∀X.X ⇒ X

2
Hindley-Milner
∀X.[X ⇒ X] ⪯ [(X ⇒ X) ⇒ (X ⇒ X)] ∀X.[X ⇒ X] ⪯ [X ⇒ X]
axv axv
[X] ⪯ [X] ∀X.[X ⇒ X] ⪯ [(X ⇒ X) ⇒ (X ⇒ X)] i : ∀X.[X ⇒ X] ⊢ i : [(X ⇒ X) ⇒ (X ⇒ X)] i : ∀X.[X ⇒ X] ⊢ i : [X ⇒ X]
axv axv ⇒e
x : [X] ⊢ x : [X] i : ∀X.[X ⇒ X] ⊢ i : [(X ⇒ X) ⇒ (X ⇒ X)] i : ∀X.[X ⇒ X] ⊢ ii : [X ⇒ X]
⇒i ⇒e
⊢ λx.x : [X ⇒ X] i : ∀X.[X ⇒ X] ⊢ i(ii) : [X ⇒ X]
let
⊢ let i = λx.x in i(ii) : [X ⇒ X]

También podría gustarte