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

Slides:



Advertisements
Similar presentations
More ML Compiling Techniques David Walker. Today More data structures lists More functions More modules.
Advertisements

Modern Programming Languages, 2nd ed.
A Third Look At ML 1. Outline More pattern matching Function values and anonymous functions Higher-order functions and currying Predefined higher-order.
Type Inference David Walker COS 320. Criticisms of Typed Languages Types overly constrain functions & data polymorphism makes typed constructs useful.
Closures & Environments CS153: Compilers Greg Morrisett.
ML Exceptions.1 Standard ML Exceptions. ML Exceptions.2 Exceptions – The Need  An extensive part of the code is error handling  A function can return.
Type Checking, Inference, & Elaboration CS153: Compilers Greg Morrisett.
CSE341: Programming Languages Lecture 2 Functions, Pairs, Lists Dan Grossman Winter 2013.
The Semantic Soundness of a Type System for Interprocedural Register Allocation and Constructor Registration Torben Amtoft Kansas State University joint.
ML Datatypes.1 Standard ML Data types. ML Datatypes.2 Concrete Datatypes  The datatype declaration creates new types  These are concrete data types,
1 How to transform an analyzer into a verifier. 2 OUTLINE OF THE LECTURE a verification technique which combines abstract interpretation and Park’s fixpoint.
Tim Sheard Oregon Graduate Institute Lecture 8: Operational Semantics of MetaML CSE 510 Section FSC Winter 2005 Winter 2005.
ML Exceptions.1 Standard ML Exceptions. ML Exceptions.2 Exceptions – The Need  An extensive part of the code is error handling  A function F can return.
Recap 1.Programmer enters expression 2.ML checks if expression is “well-typed” Using a precise set of rules, ML tries to find a unique type for the expression.
Getting started with ML ML is a functional programming language. ML is statically typed: The types of literals, values, expressions and functions in a.
ML: a quasi-functional language with strong typing Conventional syntax: - val x = 5; (*user input *) val x = 5: int (*system response*) - fun len lis =
CSE-321 Programming Languages Predicative Polymorphic -Calculus POSTECH May 23, 2007 박성우.
Chapter ElevenModern Programming Languages1 A Fourth Look At ML.
Patterns in ML functions. Formal vs. actual parameters Here's a function definition (in C): –int add (int x, int y) { return x + y; } –x and y are the.
Introduction to ML – Part 1 Frances Spalding. Assignment 1 chive/fall05/cos441/assignments/a1.ht m
ML Exceptions.1 Standard ML Exceptions. ML Exceptions.2 Exceptions – The Need  An extensive part of the code is error handling  A function can return.
CSE341: Programming Languages Lecture 4 Records (“each of”), Datatypes (“one of”), Case Expressions Dan Grossman Fall 2011.
Introduction to ML – Part 1 Kenny Zhu. Assignment 2 chive/fall07/cos441/assignments/a2.ht m
Tim Sheard Oregon Graduate Institute Lecture 6: Monads and Interpreters CSE 510 Section FSC Winter 2004 Winter 2004.
Standard ML- Part III Compiler Baojian Hua
ML: a quasi-functional language with strong typing Conventional syntax: - val x = 5; (*user input *) val x = 5: int (*system response*) - fun len lis =
01/17/20031 Guarded Recursive Datatype Constructors Hongwei Xi and Chiyan Chen and Gang Chen Boston University.
Good Advice for Type-directed Programming Aspect-oriented Programming and Extensible Generic Functions Geoffrey Washburn [ ] Joint.
Cse321, Programming Languages and Compilers 1 6/19/2015 Lecture #18, March 14, 2007 Syntax directed translations, Meanings of programs, Rules for writing.
Introduction to ML - Part 2 Kenny Zhu. What is next? ML has a rich set of structured values Tuples: (17, true, “stuff”) Records: {name = “george”, age.
Introduction to ML Last time: Basics: integers, Booleans, tuples,... simple functions introduction to data types This time, we continue writing an evaluator.
Cse321, Programming Languages and Compilers 1 6/23/2015 Lecture #15, March. 5, 2007 Judgments for mini-Java Multiple type environments Class Hierarchy.
Code Generation Compiler Baojian Hua
Closure and Environment Compiler Baojian Hua
CS 2104 : Prog. Lang. Concepts. Functional Programming I Lecturer : Dr. Abhik Roychoudhury School of Computing From Dr. Khoo Siau Cheng’s lecture notes.
1 SML fn x => e e 1 e 2 0, 1, 2,..., +, -,... true, false, if e then e else e patterns datatypes exceptions structures functors fun f x = e variables.
CSE-321 Programming Languages Introduction to Functional Programming (Part II) POSTECH March 13, 2006 박성우.
1 ML fun x -> e e 1 e 2 0, 1, 2,..., +, -,... true, false, if e then e else e patterns datatypes exceptions structures functors let f x = e variables These.
A Second Look At ML 1. Outline Patterns Local variable definitions A sorting example 2.
A Third Look At ML Chapter NineModern Programming Languages, 2nd ed.1.
Advanced Functional Programming Tim Sheard 1 Lecture 18 Advanced Functional Programming Tim Sheard Oregon Graduate Institute of Science & Technology Lecture.
CSE-321 Programming Languages -Calculus (II) POSTECH March 27, 2006 박성우.
-Calculus Kangwon National University 임현승 Programming Languages These slides are based on the slides by Prof. Sungwoo Park at POSTECH.
Chapter SevenModern Programming Languages1 A Second Look At ML.
Advanced Functional Programming Tim Sheard 1 Lecture 17 Advanced Functional Programming Tim Sheard Oregon Graduate Institute of Science & Technology Lecture:
CSE 130 : Spring 2011 Programming Languages Ranjit Jhala UC San Diego Lecture 5: Functions and Closures.
CSED101 INTRODUCTION TO COMPUTING SUM TYPE 유환조 Hwanjo Yu.
2/6/20161 Programming Languages and Compilers (CS 421) Elsa L Gunter 2112 SC, UIUC Based in part on slides by Mattox.
CSE-321 Programming Languages -Calculus (II) POSTECH March 26, 2007 박성우.
CSE-321 Programming Languages Abstract Machine E POSTECH May 1, 2006 박성우.
CSE-321 Programming Languages Dependent Types POSTECH June 5, 2006 박성우.
CSE-321 Programming Languages Introduction to Functional Programming POSTECH March 8, 2006 박성우.
1 Interactive Computer Theorem Proving CS294-9 September 7, 2006 Adam Chlipala UC Berkeley Lecture 3: Data structures and Induction.
Programming Languages and Compilers (CS 421)
Principles of programming languages 12: Functional programming
ML: a quasi-functional language with strong typing
ML Programming Language Design and Implementation (4th Edition)
Lecture 8.
Objective caml Daniel Jackson MIT Lab for Computer Science 6898: Advanced Topics in Software Design March 18, 2002.
CSE341: Programming Languages Lecture 7 First-Class Functions
Nicholas Shahan Spring 2016
Agenda SML Docs First-Class Functions Examples Standard Basis
Agenda SML Docs First-Class Functions Examples Standard Basis
CSE 341 Section 2 Winter 2018 Adapted from slides by Nick Mooney, Nicholas Shahan, Patrick Larson, and Dan Grossman.
CSE 341 Section 5 Winter 2018.
CSE-321 Programming Languages Introduction to Functional Programming
CSE 341 Section 2 Nick Mooney Spring 2017
CSE-321 Programming Languages Introduction to Functional Programming
Programming Languages and Compilers (CS 421) #3: Closures, evaluation of function applications, order of evaluation #4: Evaluation and Application.
CSE-321 Programming Languages Introduction to Functional Programming
Presentation transcript:

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

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 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 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 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 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 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 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 Outline Patterns in TML V Syntax of TML Typing and translation

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 Types scontype ::= int | bool | unit tycon ::= ty ::= scontype | tycon | (ty * ty) | (ty -> ty) | (ty)

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

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

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 Outline Patterns in TML V Syntax of TML V Typing and translation

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 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 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 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 The Remaining 1% Representation for pairs Representation for data constructors Registers Heap Optimizations 하면서 보내 버리는 시간...

Advice on Assignment 8

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

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.