CSE321 Programming Languages Letpolymorphism - PowerPoint PPT Presentation

About This Presentation
Title:

CSE321 Programming Languages Letpolymorphism

Description:

Predicative Polymorphic -Calculus. A variable is assigned a monotype. ... Predicative polymorphic -calculus. decidable type reconstruction, but useless. System F ... – PowerPoint PPT presentation

Number of Views:77
Avg rating:3.0/5.0
Slides: 26
Provided by: sungwo8
Category:

less

Transcript and Presenter's Notes

Title: CSE321 Programming Languages Letpolymorphism


1
CSE-321 Programming LanguagesLet-polymorphism
???
  • POSTECH
  • May 28, 2007

2
System F
3
Typing Rules
4
Identity Function
5
Pairing Function
6
Types in P.P. ?-Calculus
7
Predicative Polymorphic ?-Calculus
A variable is assigned a monotype.
A type application uses a monotype.
8
Useless Polytypes
  • Let's apply id to two different types bool and
    int.
  • Polytypes can be used only monomorphically.

9
Let-polymorphism
  • System F
  • powerful, but undecidable type reconstruction
  • Predicative polymorphic ?-calculus
  • decidable type reconstruction, but useless

System F
let-polymorphism
P.P. ?-calculus
10
Outline
  • System F V
  • Predicative polymorphic ?-calculus V
  • Let-polymorphism
  • Implicit polymorphism
  • Value restriction

11
Let-binding
  • let x e in e'
  • binds x to a polymorphic expression e.
  • allows multiple occurrences of x in e'.

12
Let-polymorphism
13
Reduction of let-bindings
14
Why not?
System F
15
Outline
  • System F V
  • Predicative polymorphic ?-calculus V
  • Let-polymorphism V
  • Implicit polymorphism
  • Value restriction

16
Implicit Polymorphism
  • No type abstraction, no type application
  • No type annotation in ?-abstraction
  • An expression may have multiple types
  • ?x. x
  • bool ! bool, int ! int, ..., 8?.? ! ?

17
Type System
18
8I and 8E vs. Gen and Spec
19
Gen Generalizing Types
  • Used to assign polytypes to expressions

20
Spec Specializing Types
  • Typically used to specialize types of let-bound
    variables

21
(No Transcript)
22
Outline
  • System F V
  • Predicative polymorphic ?-calculus V
  • Let-polymorphism V
  • Implicit polymorphism V
  • Value restriction

23
Prototypical Example
24
Value Restriction
  • Expression in the rule Gen must be a syntactic
    value.
  • If not, it must be used monomorphically.

25
SML Example
  • - let val id (fn y gt y) (fn z gt z) in id true
    end
  • val it true bool
  • - let val id (fn y gt y) (fn z gt z) in (id
    true, id 1) end
  • stdIn2.40-2.56 Error operator and operand don't
    agree literal
  • operator domain bool
  • operand int
  • in expression
  • id 1
  • - let val id (fn y gt y) (fn z gt z) in id end
  • stdIn1.1-1.46 Warning type vars not generalized
    because of
  • value restriction are instantiated to dummy
    types (X1,X2,...)
  • val it fn ?.X1 -gt ?.X1
Write a Comment
User Comments (0)
About PowerShow.com