cse-321 programming languages extensions to the simply typed -calculus
Post on 03-Jan-2016
19 Views
Preview:
DESCRIPTION
TRANSCRIPT
CSE-321 Programming Languages
Extensions to the Simply Typed -Calculus
POSTECH
April 10, 2006
박성우
2
Abstract Syntax
3
Operational Semantics
4
Type System
5
Outline• Product types
– pairs– generalized product types– unit type
• Sum types• Fixed point construct
6
Pairs in SML- (1, true);
val it = (1,true) : int * bool
- #1 (1, true) ;
val it = 1 : int
- #2 (1, true) ;
val it = true : bool
7
Abstract Syntax and Typing Rules
8
Eager Reduction Rules
9
Lazy Reduction Rules
10
Outline• Product types
– pairs V– generalized product types– unit type
• Sum types• Fixed point construct
11
Tuples in SML- (1, true, "hello", fn x : int => x);
val it = (1,true,"hello",fn) : int * bool * string * (int -> int)
- #1 (1, true, "hello", fn x : int => x);
val it = 1 : int
- #2 (1, true, "hello", fn x : int => x);
val it = true : bool
- #3 (1, true, "hello", fn x : int => x);
val it = "hello" : string
12
Generalized Product Types
14
Generalized Product Types
• We have n components.– n = 2
• pair types– n > 2
• tuple types– n = 1
• seems irrelevant– n = 0?
15
n = 0
16
Outline• Product types
– pairs V– generalized product types V– unit type
• Sum types• Fixed point construct
17
Unit in SML- ();
val it = () : unit
18
• We need n elements to build a tuple:
• I want to extract the i-th element where 1 · i :
n = 0: Nullary Product Type
No elimination rule for the unit type!
19
Type unit: No Elim; Only Intro
20
Outline• Product types V
– pairs– generalized product types– unit type
• Sum types• Fixed point construct
21
Datatypes in SML- datatype t = Inl of int | Inr of bool;
datatype t = Inl of int | Inr of bool
- val x = Inl 1;
val x = Inl 1 : t
- val y = Inr true;
val y = Inr true : t
- case (Inl 1) of Inl x => x | Inr _ => 0;
val it = 1 : int
- case (Inr true) of Inl x => x | Inr _ => 0;
val it = 0 : int
22
Datatypes in SML 2007- datatype 'int + bool' = Inl of int | Inr of bool;
datatype 'int + bool' = Inl of int | Inr of bool
- val x = Inl 1;
val x = Inl 1 : 'int + bool'
- val y = Inr true;
val y = Inr true : 'int + bool'
- case (Inl 1) of Inl x => x | Inr _ => 0;
val it = 1 : int
- case (Inr true) of Inl x => x | Inr _ => 0;
val it = 0 : int
23
Sum Types: Two Alternatives
24
Reduction Rules
25
bool = unit + unit
26
n = 0: Nullary Sum Type
27
What about Elimination Rule?
28
Type void: No Intro; Only Elim
29
Why do we need the Elim rule then?
• void type is not found in SML.
30
Outline• Product types V
– pairs– generalized product types– unit type
• Sum types V • Fixed point construct
31
Recursion?• Why not use the fixed point combinator?
• It does not typecheck in the simply typed -calculus.– f has type A and also A ! A.
32
Fixed Point Construct
33
Recursive Functions in SML
34
Mutually Recursive Functions in SML
top related