Tim Sheard Oregon Graduate Institute CS510 Sect FSC Winter 2004 Winter 2004 Lecture 1: Introduction.

Slides:



Advertisements
Similar presentations
Types and Programming Languages Lecture 7 Simon Gay Department of Computing Science University of Glasgow 2006/07.
Advertisements

Current Techniques in Language-based Security David Walker COS 597B With slides stolen from: Steve Zdancewic University of Pennsylvania.
The lambda calculus David Walker CS 441. the lambda calculus Originally, the lambda calculus was developed as a logic by Alonzo Church in 1932 –Church.
CS 206 Introduction to Computer Science II 01 / 20 / 2009 Instructor: Michael Eckmann.
Tim Sheard Oregon Graduate Institute Lecture 8: Operational Semantics of MetaML CSE 510 Section FSC Winter 2005 Winter 2005.
Lecture 1: Overview CMSC 201 Computer Science 1 (Prof. Chang version)
Tim Sheard Oregon Graduate Institute Lecture 4: Staging Interpreters CSE 510 Section FSC Winter 2004 Winter 2004.
1 Meta-Programming through Typeful Code Representation Chiyan Chen and Hongwei Xi Boston University.
June 13, Introduction to CS II Data Structures Hongwei Xi Comp. Sci. Dept. Boston University.
CS 330 Programming Languages 09 / 13 / 2007 Instructor: Michael Eckmann.
Advanced Compilers CSE 231 Instructor: Sorin Lerner.
Cse321, Programming Languages and Compilers 1 6/19/2015 Lecture #18, March 14, 2007 Syntax directed translations, Meanings of programs, Rules for writing.
Tim Sheard Oregon Graduate Institute Lecture 2: More on MetaML CS510 Sect FSC Winter 2004 Winter 2004.
Paper Analysis Implementing Multi-stage Languages Using ASTs, Gensym, and Reflection by Calcagno, Taha, Huang, and Leroy.
CS 206 Introduction to Computer Science II 09 / 03 / 2008 Instructor: Michael Eckmann.
Scholarship Skills Tim Sheard and Todd Leen 1 Lecture 2 Scholarship Skills Tim Sheard and Todd Leen 2006 PSU - OHSU All material © 1996, 1997, 1999, 2000.
CS 410 Applied Algorithms Applied Algorithms Lecture #1 Introduction, class information, first problems.
Tim Sheard Oregon Graduate Institute Lecture 5: Review of homework 2 CS510 Sect FSC Winter 2004 Winter 2004.
Algorithm Efficiency and Sorting
Tim Sheard Oregon Graduate Institute Lecture 11: A Reduction Semantics for MetaML CS510 Section FSC Winter 2005 Winter 2005.
9/27/2006Prof. Hilfinger, Lecture 141 Parsing Odds and Ends Lecture 14 (P. N. Hilfinger, plus slides adapted from R. Bodik)
CS 581: Introduction to the Theory of Computation Lecture 1 James Hook Portland State University
July 16, Introduction to CS II Data Structures Hongwei Xi Comp. Sci. Dept. Boston University.
Programming. Software is made by programmers Computers need all kinds of software, from operating systems to applications People learn how to tell the.
COP4020/CGS5426 Programming languages Syllabus. Instructor Xin Yuan Office: 168 LOV Office hours: T, H 10:00am – 11:30am Class website:
CS190/295 Programming in Python for Life Sciences: Lecture 1 Instructor: Xiaohui Xie University of California, Irvine.
Abstraction IS 101Y/CMSC 101 Computational Thinking and Design Tuesday, September 17, 2013 Carolyn Seaman University of Maryland, Baltimore County.
Introduction to Programming Summer 2010 Akil M. Merchant.
Welcome to CS 3260 Dennis A. Fairclough. Overview Course Canvas Web Site Course Materials Lab Assignments Homework Grading Exams Withdrawing from Class.
Staging in Haskell What is Staging What does it Mean Using Template Haskell.
Lecture 1 Page 1 CS 111 Summer 2015 Introduction CS 111 Operating System Principles.
COMP-400 Introduction and Orientation Winter 2006 January 19, 2006 School of Computer Science McGill University.
Advanced Functional Programming Tim Sheard 1 Lecture 1 Advanced Functional Programming Tim Sheard Oregon Graduate Institute of Science & Technology.
BMTRY 789 Introduction to SAS Programming Lecturer: Annie N. Simpson, MSc.
Abstraction IS 101Y/CMSC 101 Computational Thinking and Design Tuesday, September 17, 2013 Marie desJardins University of Maryland, Baltimore County.
Chapter Twenty-ThreeModern Programming Languages1 Formal Semantics.
Welcome to CS 115! Introduction to Programming. Class URL Write this down!
Java Mint: A Call for Questions Walid Taha Rice University.
Formal Semantics Chapter Twenty-ThreeModern Programming Languages, 2nd ed.1.
Algorithms CS139 – Aug 30, Problem Solving Your roommate, who is taking CS139, is in a panic. He is worried that he might lose his financial aid.
Object Oriented Programming (OOP) Design Lecture 1 : Course Overview Bong-Soo Sohn Associate Professor School of Computer Science and Engineering Chung-Ang.
Advanced Functional Programming Tim Sheard 1 Lecture 6 Functional Programming Tim Sheard & Mark Jones Monads & Interpreters.
Computational Structures Tim Sheard & James Hook Portland State University Class Preliminaries.
IST 210: Organization of Data
Scholarship Skills Andrew Black 1 Lecture 1 Scholarship Skills Andrew P Black Winter 2013 All material © 1996–2012 David Maier, Tim Sheard, Andrew Black,
Algorithms CS280 – 10/20/05. Announcement  Part 1 of project 2 due.  Read chapters 10, 7 for this unit  Tuesday we will also be in the classroom We.
Advanced Functional Programming Tim Sheard 1 Lecture 17 Advanced Functional Programming Tim Sheard Oregon Graduate Institute of Science & Technology Lecture:
1 CS 381 Introduction to Discrete Structures Lecture #1 Syllabus Week 1.
Review of the numeration systems The hardware/software representation of the computer and the coverage of that representation by this course. What is the.
CSE 1340 Introduction to Computing Concepts Class 1 ~ Intro.
Computer Networks CNT5106C
CS 367 Introduction to Data Structures Charles N. Fischer Fall s367.html.
FUNCTIONAL PROGRAMING AT WORK - HASKELL AND DOMAIN SPECIFIC LANGUAGES Dr. John Peterson Western State Colorado University.
CSE 341 : Programming Languages Lecture 9 Lexical Scope, Closures Zach Tatlock Spring 2014.
CSc 120 Introduction to Computer Programing II
The need for Programming Languages
Tim Sheard Oregon Graduate Institute
CS190/295 Programming in Python for Life Sciences: Lecture 1
CSE341: Programming Languages Lecture 8 Lexical Scope and Function Closures Dan Grossman Winter 2013.
CSE341: Programming Languages Lecture 8 Lexical Scope and Function Closures Dan Grossman Spring 2013.
The Metacircular Evaluator
The Metacircular Evaluator
CSE341: Programming Languages Lecture 8 Lexical Scope and Function Closures Dan Grossman Spring 2016.
Background In his classic 1972 paper on definitional interpreters, John Reynolds introduced two key techniques: Continuation-passing style - Makes.
CSE341: Programming Languages Lecture 8 Lexical Scope and Function Closures Dan Grossman Autumn 2018.
CSE341: Programming Languages Lecture 8 Lexical Scope and Function Closures Zach Tatlock Winter 2018.
6.001 SICP Variations on a Scheme
CSE341: Programming Languages Lecture 8 Lexical Scope and Function Closures Dan Grossman Autumn 2017.
CSE341: Programming Languages Lecture 8 Lexical Scope and Function Closures Dan Grossman Spring 2019.
Brett Wortzman Summer 2019 Slides originally created by Dan Grossman
Presentation transcript:

Tim Sheard Oregon Graduate Institute CS510 Sect FSC Winter 2004 Winter 2004 Lecture 1: Introduction

2Cse583 Winter 2002 Acknowledgements: I would like to thank all the people who have collaborated with me over the years on staged computation Jim Hook Walid Taha Zino Benaissa Eugenio Moggi Emir Pasalic Bill Harrison Nathan Linger

3Cse583 Winter 2002 Contact Details: Tim Sheard: Office: FAB115 Telephone: (503) CS510 Section FSC Home PAGE:

4Cse583 Winter 2002 Time and Location: Currently scheduled: Neuberger 220 Tues & Thurs, 4:00 – 5:15 pm;

5Cse583 Winter 2002 Methods of assessment: ElementWeight Homework (8 homeworks, mostly small programming assignments, and one or more paper presentations. Programming assignments can be done in MetaML, Template Haskell, or MetaOcaml) 40% Midterm (week 6)30% Final project (including a write up and a presentation) 30% TOTAL100%

6Cse583 Winter 2002 Policies: By default, all deadlines are firm. We will be as flexible as possible in accommodating special circumstances; but advance notice will make this a lot easier. We follow the standard PSU guidelines for academic integrity. Discussion is good; Items turned in should be your own, individual work.

7Cse583 Winter 2002 Academic Integrity Students are expected to be honest in their academic dealings. Dishonesty is dealt with severely. Homework. Pass in only your own work. Program assignments. Program independently. Examinations. Notes and such, only as the instructor allows. Homework. OK to discuss how to solve problems with other students, but each student should write up, debug, and turn in his own solution.

8Cse583 Winter 2002 Prerequisites: Programming knowledge. Knowledge of ML is a plus but not necessary if you’re willing to pick it up as we proceed Curiosity about how programs can be made more efficient.

9Cse583 Winter 2002 Course Text: None. Readings from primary sources (conferences, journals, manuals) instead I will update the readings list on the class home page as the course proceeds.

10Cse583 Winter 2002 Today’s Assignments Reading assignment Read the paper: Using MetaML: a staged Programming language. From the Lecture notes of the Summer School on Advanced Functional Programming. September Braga, Portugal. (see home page for link) Programming assignment Find or install a copy of MetaML, Template Haskell, or MetaOCaml. A MetaML package will be added to the PSU PCAT systems soon. On Thursday you will be given an assignment to write a staged program (however small) and hand it in one week from today. Never too early to get started.

11Cse583 Winter 2002 Proposed Syllabus: Intro to MetaML Using Staging Annotations Staging as fine control of evaluation order Example: Staging an Interpreter Uses of staging Partial Evaluation Monads - staging as monadic computation Semantics of staging Implementing staging Other approaches to staging Type systems for staging

12Cse583 Winter 2002 What is Staging? Staging: programs that proceed in stages. Each stage “writes” a program to run in the next stage. Examples: Compilers Partial evaluators Run-time code generation. Staging is a kind of Meta Programming

13Cse583 Winter 2002 What is Meta-programming? (at least) Two languages meta-language object-language(s) Meta-programs manipulate object- programs An object-program is a data-structure representing a sentence in a formal language.

14Cse583 Winter 2002 What can they do? Meta-programs create new program fragments compose program fragments observe the structure of program fragments Examples compilers and interpreters type checkers theorem provers program generators transformation systems program analyzers

15Cse583 Winter 2002 What is staging used for? Performance generate a family of specialized solutions Partial Evaluation Translation Reasoning Mobile – extensional code, proof carrying code Visualization and pedagogy

16Cse583 Winter 2002 How does it help? Resource aware programming Underlying cost model Programmer has fine control over cost of programs Cost might be space, time or other aspects Staging allows the programmer to control evaluation order

17Cse583 Winter 2002 Controlling Evaluation Order We want more than just the correct result! We want to control resources without resorting to tricks or unnatural programming styles.

18Cse583 Winter 2002 Traditional Approaches Fixed evaluation order with language extensions  Lazy - Outermost add strictness annotations  Strict - Innermost add annotations like force and delay Encode laziness using lambda in a strict setting datatype 'a lazylist = lazyNil | lazyCons of 'a * (unit -> 'a lazylist); fun count n = lazyCons(n, fn () => count (n+1))

19Cse583 Winter 2002 Limitations None of these approaches allow computation in the definition of a function before it is called! This is sometimes just what is needed. For example: fun power n = (fn x => if n=0 then 1 else x * (power (n-1) x)) power 2; A local unnamed function

20Cse583 Winter 2002 Reduction rules Function Definition (unfolding) fun f x y = body f act1 act2  body[act1/x, act2/y] E.g. fun f x = (x,x+1) f 34  (34,34+1) Beta-rule (fn x => body) value  body[value/x] E.g. (fn x => x – 9) 32  If-rule if True then x else y  x if False then x else y  y Primitive operators  9

21Cse583 Winter 2002 Example reduction (power 2) unfold the definition (fn x => if 2=0 then 1 else x * (power (2-1) x)) perform the if, under the lambda (fn x => x * (power (2-1) x)) unfold power again (fn x => x * ((fn x => if 1=0 then 1 else x * (power (1-1) x)) x)) use the beta rule to apply the explicit lambda to x

22Cse583 Winter 2002 Example (cont.) (fn x => x * (if 1=0 then 1 else x * (power (1-1) x))) perform the if (fn x => x * (x * (power (1-1) x))) unfold power again (fn x => x * (x * ((fn x => if 0=0 then 1 else x * (power (0-1) x))) x)) use the beta rule to apply the explicit lambda to x (fn x => x * (x * (if 0=0 then 1 else x * (power (0-1) x)))) perform the if (fn x => x * (x * 1))

23Cse583 Winter 2002 Solution - Use rich staging annotations Brackets:  no reductions allowed in e  delay computation  if e:t then : (pronounced code of t) Escape: ~ e  relax the no reduction rule of brackets above  Escape may only occur inside Brackets  splice code together to build larger code Run: run e  remove outermost brackets  force computations which have been delayed

24Cse583 Winter 2002 Rules for code Introduction rule for code 1st elimination rule for code (escape-bracket elim) … > --->  ~ must appear inside enclosing brackets  e must be escape free 2nd elimination rule for code (run-bracket elim) run ---> e  provided e has no escapes

25Cse583 Winter 2002 Power example revisited (* power : int -> -> *) fun power n = fn x => if n=0 then else (* ans : int > *) val ans = ~(power 2 ) >;

26Cse583 Winter 2002 ~ (power 2 ) > ~(if 2=0 then else * ~(power (2-1) ) >)> ~ * ~(power (2-1) ) >>) ~ ) >>) ~< z * ~(if 1=0 then else * ~(power (1-1) ) >) >>)

27Cse583 Winter 2002 ~ * ~(power (1-1) ) >>> ~ ) >>> ~ >>> ~ >> ~ > z * z * 1>

28Cse583 Winter 2002 Annotations separate the meta-program from the object-program fragments Can be placed manually. MetaML, MetaOCaml, and generating extensions Can be placed automatically. Offline partial evaluation. Must have semantic meaning. Examples: Quasi-quote notation, monadic boundaries, abstract data-structures Annotations

29Cse583 Winter 2002 Why is Staging hard? Programs are complex  Languages have features to manage complexity type systems (catch bad programs) scoping mechanisms (hide superfluous names) abstraction mechanisms (hide details) Staged programs deal with the complexity twice. Staged programming languages know about the features of the object-language. Provide reusable solutions to common problems (typing, binding, name generation...)

30Cse583 Winter 2002 Introduction to MetaML MetaML: a language for writing staged programs  What Infrastructure is possible in a language designed to help support the algorithmic construction of other programs? Advantages of MetaML  MetaML knows about staging and its inherent problems (see lecture 2)  capture knowledge  efficient solutions  design ideas can be communicated and shared

31Cse583 Winter 2002 Building pieces of code -| ; val it = : -| ; val it = : -| ; val it = : -| x + 5>; val it = a %+ 5)> : int> -| >; val it = )> : >

32Cse583 Winter 2002 Let’s try it ! Run MetaML

33Cse583 Winter 2002 Composing pieces of code -| val x = ; val x = : -| val y = ; val y = : -| fun pair x = ; val pair = Fn : ['b]. -> -| pair ; val it = :

34Cse583 Winter 2002 Executing constructed code -| val x = ; val x = : -| run x; val it = 36 : int -| fun id x = x; val id = Fn : ['a].'a -> 'a -| val q = ) >; val q = : -| run q; val it = 6 : int

35Cse583 Winter 2002 Multi-stage code -| val z = >; val z = )> : > -| val f = run z; val f = Fn : int -> -| f 12; val it = : -| run it; val it = 13 : int

36Cse583 Winter 2002 Next time More about MetaML Insight into the problems that staged programs run into Some significant examples