cse-321 programming languages (so many topics)

23
CSE-321 Programming Languages (So Many Topics) POSTECH May 29, 2006 박박박

Upload: galya

Post on 14-Jan-2016

39 views

Category:

Documents


6 download

DESCRIPTION

CSE-321 Programming Languages (So Many Topics). 박성우. POSTECH May 29, 2006. Outline for Today's Lecture. Existential types Dependent types Call-by-name and call-by-need CPS (Continuation-passing style) transformation Constructive logic Curry-Howard isomorphism - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: CSE-321 Programming Languages (So Many Topics)

CSE-321 Programming Languages

(So Many Topics)

POSTECH

May 29, 2006

박성우

Page 2: CSE-321 Programming Languages (So Many Topics)

2

Outline for Today's Lecture• Existential types• Dependent types• Call-by-name and call-by-need• CPS (Continuation-passing style) transformation• Constructive logic• Curry-Howard isomorphism• Module system of Standard ML• -calculus• LF type theory• Twelf for mechanizing proofs

Page 3: CSE-321 Programming Languages (So Many Topics)

3

List Reversal in TML

datatype list = Nil | Cons of (int * list);

val rec append = fn Nil => (fn x => Cons (x, Nil)) | Cons (h, t) => (fn x => Cons (h, append t x));

val rec reverse = fn Nil => Nil | Cons (h, t) => append (reverse t) h;

val l = Cons (1, Cons (2, Cons (3, Cons (4, Nil))));

val id = fn x => x;

id reverse l

Page 4: CSE-321 Programming Languages (So Many Topics)

4

Data Constructors in TML

datatype list = Nil | Cons of (int * list);

val rec append = fn Nil => (fn x => Cons (x, Nil)) | Cons (h, t) => (fn x => Cons (h, append t x));

val rec reverse = fn Nil => Nil | Cons (h, t) => append (reverse t) h;

val l = Cons (1, Cons (2, Cons (3, Cons (4, Nil))));

val id = fn x => x;

id reverse l

Page 5: CSE-321 Programming Languages (So Many Topics)

5

Patterns in TML

datatype list = Nil | Cons of (int * list);

val rec append = fn Nil => (fn x => Cons (x, Nil)) | Cons (h, t) => (fn x => Cons (h, append t x));

val rec reverse = fn Nil => Nil | Cons (h, t) => append (reverse t) h;

val l = Cons (1, Cons (2, Cons (3, Cons (4, Nil))));

val id = fn x => x;

id reverse l

Page 6: CSE-321 Programming Languages (So Many Topics)

6

More Patterns in TML

datatype list = Nil | Cons of (int * list);

val rec append = fn Nil => (fn x => Cons (x, Nil)) | Cons (h, t) => (fn x => Cons (h, append t x));

val rec reverse = fn Nil => Nil | Cons (h, t) => append (reverse t) h;

val l = Cons (1, Cons (2, Cons (3, Cons (4, Nil))));

val id = fn x => x;

id reverse l

Page 7: CSE-321 Programming Languages (So Many Topics)

7

Patterns

val _ = 1;

val true = true;

val Cons (h, t) = Cons (1, Nil);

val (x, y) = (1, ~1);

val (x) = 1;

val (x : int) = 1;

Page 8: CSE-321 Programming Languages (So Many Topics)

8

Match Rule : pat => exp

datatype list = Nil | Cons of (int * list);

val rec append = fn Nil => (fn x => Cons (x, Nil)) | Cons (h, t) => (fn x => Cons (h, append t x));

val rec reverse = fn Nil => Nil | Cons (h, t) => append (reverse t) h;

val l = Cons (1, Cons (2, Cons (3, Cons (4, Nil))));

val id = fn x => x;

id reverse l

Page 9: CSE-321 Programming Languages (So Many Topics)

9

Outline• Patterns in TML V• Syntax of TML• Typing and translation

Page 10: CSE-321 Programming Languages (So Many Topics)

10

Syntax for TML• scontype  ::= int  |  bool  |  unit• sconpat  ::= num  |  true  |  false  |  ()• scon  ::= num  |  true  |  false  |  ()  • op  ::= +  |  -  | *  |  =  |  <>• ty  ::= scontype  |  tycon  |  (ty * ty)  | (ty -> ty)  |  (ty)• pat  ::= _  |  sconpat  |  vid <pat>  |  (pat, pat)  |  (pat)  |  (pat : ty)• num  ::= <integer constants>• tycon  ::= <alphanumeric identifiers>• vid  ::= <alphanumeric identifiers>• conbinding  ::= vid <of ty>• conbind  ::= conbinding <| conbind>• dec  ::= val pat = exp  |  val rec pat = exp  |  datatype tycon = conbind• mrule  ::= pat => exp• match  ::= mrule <| match>• exp  ::= scon  |  vid  |  (exp, exp)  |  let dec in exp end   | (exp)  |  exp exp   | 

exp op exp   |  (exp : ty) | fn match• dlist  ::= <dec;>*• program  ::= dlist exp

Page 11: CSE-321 Programming Languages (So Many Topics)

11

Types• scontype  ::= int  |  bool  |  unit

• tycon  ::= <alphanumeric identifiers>

• ty  ::= scontype  |  tycon  |  (ty * ty)  | (ty -> ty)  |  (ty)

Page 12: CSE-321 Programming Languages (So Many Topics)

12

Patterns• sconpat  ::= num  |  true  |  false  |  ()

• vid  ::= <alphanumeric identifiers>

• pat  ::= _  |  sconpat  |  vid <pat>  |  (pat, pat)  |  (pat)  |  (pat : ty)

Page 13: CSE-321 Programming Languages (So Many Topics)

13

Declarations• vid  ::= <alphanumeric identifiers>• conbinding  ::= vid <of ty>• conbind  ::= conbinding <| conbind>• dec  ::= 

val pat = exp  |  val rec pat = exp  |  datatype tycon = conbind

Page 14: CSE-321 Programming Languages (So Many Topics)

14

Expressions and Programs • scon  ::= num  |  true  |  false  |  ()  • op  ::= +  |  -  | *  |  =  |  <>• mrule  ::= pat => exp• match  ::= mrule <| match>• exp  ::= 

scon  |  vid  |  (exp, exp)  |  let dec in exp end   |(exp)  |  exp exp   | exp op exp   |  (exp : ty)

| fn match• dlist  ::= <dec;>*• program  ::= dlist exp

Page 15: CSE-321 Programming Languages (So Many Topics)

15

Outline• Patterns in TML V• Syntax of TML V• Typing and translation

Page 16: CSE-321 Programming Languages (So Many Topics)

16

Monomorphic Typing• No polymoprhic types, i.e., no type variables

– every expression has a unique monomorphic type

val id = fn x => x;

id 1

Page 17: CSE-321 Programming Languages (So Many Topics)

17

Typing and Translation• Ast.program

– source program• Core.programty

– program with type annotations• Mach.code

– machine code

• val tprogram : Ast.program -> Core.programty

• val programty2code : Core.programty -> Mach.code

Page 18: CSE-321 Programming Languages (So Many Topics)

18

50% of Assignment 8type venv = (avid, loc) dicttype env = venv * int

val pat2code : Mach.label * Mach.label * loc -> Core.pat ->

Mach.code * venv val exp2code :

env * Mach.label -> Core.exp -> Mach.code * Mach.rvalue

val dec2code : env * Mach.label -> Core.dec ->

Mach.code * env val matchty2code :

env * Mach.label -> Core.matchty -> Mach.code

Page 19: CSE-321 Programming Languages (So Many Topics)

19

The Remaining 49%• Representation for functions• Representation for recursive functions• Context switch• Function arguments and return values

) These questions test your understanding of closures.

Page 20: CSE-321 Programming Languages (So Many Topics)

20

The Remaining 1%• Representation for pairs• Representation for data constructors• Registers• Heap• Optimizations

• 하면서 보내 버리는 시간

• ...

Page 21: CSE-321 Programming Languages (So Many Topics)

Advice on Assignment 8

Page 22: CSE-321 Programming Languages (So Many Topics)

22

• Don't get scared by Parjong's misleading message on the discussion board.

제 목 : 허허허 .. ㅠ _ ㅠ교수님 HW8.. 도저히 .. -_-aa 그 시간에 끝낼 수 있을

거라는 생각이 안드는데요 ;;

– Everyone of you can finish this assignment!

Page 23: CSE-321 Programming Languages (So Many Topics)

23

• Assignment 8– will be the most fun of all the assignments this

course offers.– will be the most rewarding experience you can

have in this course.

• Discuss with your classmates (not just with your partner)

• Start early!

• Sample solution: about 600 lines of code– You will write 300 ~ 500 lines of code.