Type Systems and Object- Oriented Programming John C. Mitchell Stanford University.

Slides:



Advertisements
Similar presentations
Type Systems and Object- Oriented Programming (III) John C. Mitchell Stanford University.
Advertisements

Computational Models The exam. Models of computation. –The Turing machine. –The Von Neumann machine. –The calculus. –The predicate calculus. Turing.
Adapted from Scott, Chapter 6:: Control Flow Programming Language Pragmatics Michael L. Scott.
Elements of Lambda Calculus Functional Programming Academic Year Alessandro Cimatti
Functional Programming. Pure Functional Programming Computation is largely performed by applying functions to values. The value of an expression depends.
Lambda Calculus and Lisp PZ03J. Lambda Calculus The lambda calculus is a model for functional programming like Turing machines are models for imperative.
Programming Languages Marjan Sirjani 2 2. Language Design Issues Design to Run efficiently : early languages Easy to write correctly : new languages.
INF 212 ANALYSIS OF PROG. LANGS Type Systems Instructors: Crista Lopes Copyright © Instructors.
INF 212 ANALYSIS OF PROG. LANGS LAMBDA CALCULUS Instructors: Crista Lopes Copyright © Instructors.
Fall Semantics Juan Carlos Guzmán CS 3123 Programming Languages Concepts Southern Polytechnic State University.
MATHEMATICAL FOUNDATIONS SUPPLEMENTAL MATERIAL – NOT ON EXAM.
Catriel Beeri Pls/Winter 2004/5 functional-language 1 Substitution Semantics of FL – a simple functional language FL is EL + (non-recursive) function creation.
Advanced Formal Methods Lecture 2: Lambda calculus Mads Dam KTH/CSC Course 2D1453, Some material from B. Pierce: TAPL + some from G. Klein, NICTA.
Foundations of Programming Languages: Introduction to Lambda Calculus
6. Introduction to the Lambda Calculus. © O. Nierstrasz PS — Introduction to the Lambda Calculus 6.2 Roadmap  What is Computability? — Church’s Thesis.
School of Computing and Mathematics, University of Huddersfield CAS810: WEEK 3 LECTURE: LAMBDA CALCULUS PRACTICAL/TUTORIAL: (i) Do exercises given out.
13. Summary, Trends, Research. © O. Nierstrasz PS — Summary, Trends, Research Summary, Trends, Research...  Summary: functional, logic and object-oriented.
Functional programming: LISP Originally developed for symbolic computing Main motivation: include recursion (see McCarthy biographical excerpt on web site).
Programming Language Semantics Mooly SagivEran Yahav Schrirber 317Open space html://
Chair of Software Engineering 1 Concurrent Object-Oriented Programming Arnaud Bailly, Bertrand Meyer and Volkan Arslan.
C SC 520 Principles of Programming Languages 1 C SC 520: Principles of Programming Languages Peter J. Downey Department of Computer Science Spring 2006.
Semantics with Applications Mooly Sagiv Schrirber html:// Textbooks:Winskel The.
Functional programming: LISP Originally developed for symbolic computing First interactive, interpreted language Dynamic typing: values have types, variables.
C. Varela1 Lambda Calculus alpha-renaming, beta reduction, applicative and normal evaluation orders, Church-Rosser theorem, combinators Carlos Varela Rennselaer.
Dr. Muhammed Al-Mulhem ICS An Introduction to Functional Programming.
314450: PROGRAMMING PARADIGMS Teaching scheme: Examination Scheme: Lectures: 3 Hours/Week Theory: 100 Marks OBJECTIVE: To understand the basic building.
Functional Programming Element of Functional Programming.
Imperative Programming
Program Analysis and Verification Spring 2015 Program Analysis and Verification Lecture 2: Operational Semantics I Roman Manevich Ben-Gurion University.
CSE S. Tanimoto Lambda Calculus 1 Lambda Calculus What is the simplest functional language that is still Turing complete? Where do functional languages.
Lambda Calculus History and Syntax. History The lambda calculus is a formal system designed to investigate function definition, function application and.
© Kenneth C. Louden, Chapter 11 - Functional Programming, Part III: Theory Programming Languages: Principles and Practice, 2nd Ed. Kenneth C. Louden.
A Theory of Hygienic Macros David Herman, Mitchell Wand Northeastern University.
ISBN Chapter 3 Describing Semantics -Attribute Grammars -Dynamic Semantics.
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.
1 Programming Languages Fundamentals Cao Hoaøng Truï Khoa Coâng Ngheä Thoâng Tin Ñaïi Hoïc Baùch Khoa TP. HCM.
© Kenneth C. Louden, Chapter 11 - Functional Programming, Part III: Theory Programming Languages: Principles and Practice, 2nd Ed. Kenneth C. Louden.
CSE 230 The -Calculus. Background Developed in 1930’s by Alonzo Church Studied in logic and computer science Test bed for procedural and functional PLs.
Program Analysis and Verification Spring 2014 Program Analysis and Verification Lecture 4: Axiomatic Semantics I Roman Manevich Ben-Gurion University.
TIVDM2Functional Programming Language Concepts 1 Concepts from Functional Programming Languages Peter Gorm Larsen.
Programming Languages and Design Lecture 3 Semantic Specifications of Programming Languages Instructor: Li Ma Department of Computer Science Texas Southern.
Logical and Functional Programming
1-1 An Introduction to Functional Programming Sept
-Calculus Kangwon National University 임현승 Programming Languages These slides are based on the slides by Prof. Sungwoo Park at POSTECH.
Lambda Calculus CSE 340 – Principles of Programming Languages Fall 2015 Adam Doupé Arizona State University
1-1 1 Introduction  Programming linguistics: concepts and paradigms syntax, semantics, and pragmatics language processors.  Historical development of.
1 FP Foundations, Scheme In Text: Chapter Chapter 14: FP Foundations, Scheme Mathematical Functions Def: A mathematical function is a mapping of.
CS7120 (Prasad)L13-1-Lambda-Opt1 Typed Lambda Calculus Adapted from Lectures by Profs Aiken and Necula of Univ. of California at Berkeley.
CSE 425: Functional Programming I Programs as Functions Some programs act like mathematical functions –Associate a set of input values from the function’s.
PPL Syntax & Formal Semantics Lecture Notes: Chapter 2.
6/21/20161 Programming Languages and Compilers (CS 421) Reza Zamani Based in part on slides by Mattox Beckman,
Arvind Computer Science and Artificial Intelligence Laboratory M.I.T. L03-1 September 14, 2006http:// -calculus: A Basis for.
COMP 412, FALL Type Systems C OMP 412 Rice University Houston, Texas Fall 2000 Copyright 2000, Robert Cartwright, all rights reserved. Students.
Chapter 2: Lambda Calculus
Functional Programming
Functional Programming Languages
Functional Programming
Unit – 3 :LAMBDA CALCULUS AND FUNCTIONAL PROGRAMMING
Lambda Calculus CSE 340 – Principles of Programming Languages
PROGRAMMING LANGUAGES
CS 326 Programming Languages, Concepts and Implementation
CS 611: Lecture 9 More Lambda Calculus: Recursion, Scope, and Substitution September 17, 1999 Cornell University Computer Science Department Andrew Myers.
Programming Languages and Compilers (CS 421)
FP Foundations, Scheme In Text: Chapter 14.
Denotational Semantics (Denotational Semantics)
Announcements Quiz 6 HW7 due Tuesday, October 30
Defining A Formal Semantics For The Rosetta Specification Language
CSE S. Tanimoto Lambda Calculus
Programming Languages
Presentation transcript:

Type Systems and Object- Oriented Programming John C. Mitchell Stanford University

Plan for these lectures l Foundations; type-theoretic framework l Principles of object-oriented programming l Decomposition of OOP into parts l Formal models of objects

Goals l Understand constituents of object- oriented programming l Insight may be useful in software design l Trade-offs in program structure l Possible research opportunities »language design »formal methods »system development, reliability, security

Applications of type systems l Methodology »Design expressed through types relationships. l Security »Prevent “message not understood.'' l Efficiency »Eliminate run-time tests. »Optimize method lookup. l Analysis »Debugger, tree-shaking, etc.

Research in type systems l Repair insecurities and deficiencies in existing typed languages. l Find better type systems » Flexible OOP without type case and casts l Basis for formal methods »Formulas-as-types analogy »No Hoare logic for sequential objects

Specific Opportunities l Typed, sequential OOP Conventional Object-oriented Lisp Smalltalk ML ?? C C ++ l Improvements in C++, Java l Concurrency, distributed systems

Type Systems and Object- Oriented Programming PART I John C. Mitchell Stanford University

Foundations for Programming l Computability theory l Lambda Calculus l Denotational Semantics l Logics of Programming

Computability Theory l A function f : N -> N is computable if »there is a program that computes it »there is an idealized machine computing it l Reductions: compute one function using another as subroutine l Compare degrees of computability l Some functions cannot be computed

Inductive def’n of computable l Successor function, constant function, projection f(x,y,z) = x are computable l Composition of computable functions l Primitive recursion f(0,x) = g(x) f(n+1, x) = h(n, x, f(n,x)) l Minimalization f(x) = the least y such that g(x,y) = 0

Turing machine l infinite tape with 0, 1, blank l read/write tape head l finite-state control

Strengths of Computability l Robust theory »equiv language and machine definitions l Definition of “universal” »Confidence that all computable functions are definable in a programming language l Useful measures of time, space

Weaknesses l Formulated for numeric functions only l Need “equivalence” for program parts »optimization, transformation, modification l Limited use in programming pragmatics »Are Lisp, Pascal and C equally useful? »Turing Tarpit

Lambda Calculus l early language model for computability l syntax »function expressions »free and bound variables; scope l evaluation of expressions l equational logic

Untyped Lambda Calculus l Write  x. e for “the function f with f(x) = e” l Example f. f(f(a)) apply function argument twice to a l Symbolic evaluation by “reduction”  f. f(f(a)) )( x. b) => ( x. b) ( ( x. b) a ) => ( x. b) ( b ) => b

Syntactic concepts l Variable x is free in f( g(x) ) l Variable y is bound in ( y. y(x))( x. x) l The scope of binding y is y(x) l  conversion ( x.... x... x... )= ( y.... y... y... ) l Declaration let x = e_1 in e_2 ::= ( x. e_2) e_1

The syntax behind the syntax function f(x); begin; return ((x+5)*(x+3)); end; f(4+2); is just another way of writing let f = ( x. ((x+5)*(x+3)) ) in f(4+2)

Equational Proof System  ( x.... x... x... ) = ( y.... y... y... )  ( x. e_1) e_2 = [e_2/x] e_1 rename bound var in e_1 to avoid capture  x. e x = e x not free in e

Rationale for  l Axiom: x. e x = e x not free in e l Suppose e is function expression y. e’ l Then by  and  we have  x. ( y. e’) x = x. ([x/y] e’) = y. e’ l But  not needed in computation

Why the Greek letter ? l Dana Scott told me this once: »Dana asked Addison, at Berkeley »Addison is Church’s son-in-law »Addison had asked Church »Church said, “eeny, meeny, miny, mo”

Symbolic Evaluation (reduction)  ( x.... x... x... ) = ( y.... y... y... )  ( x. e_1) e_2 => [e_2/x] e_1 rename bound var in e_1 to avoid capture  x. e x => e x not free in e but this is not needed for closed “programs”

Lambda Calculus Hacking (I) l Numerals n = f. x. f (f... f(x)...) with n f’s l Successor Succ n = f. x. f ( n (f) (x) ) l Addition Add n m = n Succ m

Lambda Calculus Hacking (II) l Nontermination  x. x (x) )  y. y (y) ) => [  x. x (x) ) / y] y (y) =  y. y (y) )  y. y (y) ) l Fixed-point operator Y f = f (Y f) Y = f.  x. f (x (x) ))  x. f (x (x) )) Y f =>  x....)  x....) => f (  x....)  x....))

Lambda Calculus Hacking (III) Write factorial function f(x) = if x=0 then 1 else x*f(x-1) As Y (factbody) where factbody = f. x.Cond (Zero? x)(1)( Mult( x )( f (Pred x)) )

Lambda Calculus Hacking (IV) Calculate by reduction Y (factbody) ( 5 ) => f. x.Cond (Zero? x)(1)( Mult( x )( f (Pred x)) ) (Y (factbody) ) ( 5 ) => Cond (Zero? 5) ( 1 ) ( Mult( 5 ) ( (Y (factbody) ) (Pred 5) )

Insight l A recursive function is a fixed point fun f(x) = if x=0 then 1 else x*f(x-1) means let f be the fixed point of the functional f. x.Cond (Zero? x)(1)( Mult(x) (f(Pred x)) ) l Not just “mathematically” but also “computationally”

Extensions of Lambda Calculus l Untyped lambda calculus is unstructured theory of functions l Add types »separate functions from non-functions »add other kinds of data –integers, booleans, strings, stacks, trees,... »provide program-structuring facilities –modules, abstract data types,...

Pros and Cons of Lambda Calculus l Includes syntactic structure of programs l Equational logic of programs l Symbolic computation by reduction l Mathematical structure (with types) provided by categorical concepts l Still, largely intensional theory with few mathematical methods for reasoning

Denotational Semantics l Can be viewed as model theory of typed lambda calculus l Interpret each function as continuous map on appropriate domains of values l Satisfy provable equations, and more l Additional reasoning principles (induction)

Type-theoretic framework l Typed extensions of lambda calculus l Programming lang. features are types »Recursive types for recursion »Exception types for exceptions »Module types for modules »Object types for objects l Operational and denotational models l Equational, other logics (Curry-Howard)

Imperative programs l Traditional denotational semantics »translate imperative programs to functional programs that explicitly manipulate a store l Lambda calculus with assignment »give direct operational semantics using location names »(compositional denotational semantics only by method above, as far as I know) l Similar issues for concurrency

Plan for these lectures 3 Foundational framework type theory, operational & denotational sem. l Principles of object-oriented programming l Decomposition of OOP into parts l Type-theoretic basis for OOP

Q: What is a type? l Some traditional answers »a set of values (object in a category) »a set together with specified operations l Bishop’s constructive set »membership predicate, equivalence relation l Syntactic answer »type expresion (or form) »introduction and elimination rules »equation relating introduction and elimination

Example: Cartesian Product »Type expression: A  B »Introduction rule: x : A y : B  x, y  : A  B »Elimination rule: p: A  B first(p) : A second(p) : B »Equations: intro  elim = identity first  x, y  = x second  x, y  = y  first(p), second(p)  = p

Adjoint Situation l Natural Iso Maps(FA, B)  Maps(A, GB) l Cartesian Product on category C »Category C  C with  f, g   a, b   c,d  »Functor F : C  C  C with F(a) =  a, a  »Cartesian product is right adjoint of F »Maps(  a, a ,  b, c  )  Maps(a, b  c )  a, a    b, c  a  b  c