Presentation is loading. Please wait.

Presentation is loading. Please wait.

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

Similar presentations


Presentation on theme: "CSE-321 Programming Languages (So Many Topics) POSTECH May 29, 2006 박성우."— Presentation transcript:

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

2 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

3 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

4 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

5 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

6 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

7 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;

8 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

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

10 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 : ty) num ::= tycon ::= vid ::= conbinding ::= vid conbind ::= conbinding dec ::= val pat = exp | val rec pat = exp | datatype tycon = conbind mrule ::= pat => exp match ::= mrule exp ::= scon | vid | (exp, exp) | let dec in exp end | (exp) | exp exp | exp op exp | (exp : ty) | fn match dlist ::= * program ::= dlist exp

11 11 Types scontype ::= int | bool | unit tycon ::= ty ::= scontype | tycon | (ty * ty) | (ty -> ty) | (ty)

12 12 Patterns sconpat ::= num | true | false | () vid ::= pat ::= _ | sconpat | vid | (pat, pat) | (pat) | (pat : ty)

13 13 Declarations vid ::= conbinding ::= vid conbind ::= conbinding dec ::= val pat = exp | val rec pat = exp | datatype tycon = conbind

14 14 Expressions and Programs scon ::= num | true | false | () op ::= + | - | * | = | <> mrule ::= pat => exp match ::= mrule exp ::= scon | vid | (exp, exp) | let dec in exp end | (exp) | exp exp | exp op exp | (exp : ty) | fn match dlist ::= * program ::= dlist exp

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

16 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

17 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

18 18 50% of Assignment 8 type venv = (avid, loc) dict type 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

19 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.

20 20 The Remaining 1% Representation for pairs Representation for data constructors Registers Heap Optimizations 하면서 보내 버리는 시간...

21 Advice on Assignment 8

22 22 Don't get scared by Parjong's misleading message on the discussion board. 제 목 : 허허허.. ㅠ _ ㅠ 교수님 HW8.. 도저히.. -_-aa 그 시간에 끝낼 수 있을 거라는 생각이 안드는데요 ;; –Everyone of you can finish this assignment!

23 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.


Download ppt "CSE-321 Programming Languages (So Many Topics) POSTECH May 29, 2006 박성우."

Similar presentations


Ads by Google