![Page 1: Lecture1 Introduction 24January2011 - Cornell University€¦ · CourseGoals • Learntechniquesformodelingprograms∗ I Formalsemantics(operational,axiomatic,denotational) I Extendtoadvancedlanguagefeatures](https://reader033.vdocuments.pub/reader033/viewer/2022060518/604b93c2673ed862535917d5/html5/thumbnails/1.jpg)
.
.
CS 6110 — AdvancedProgramming Languages
Lecture 1Introduction
24 January 2011
![Page 2: Lecture1 Introduction 24January2011 - Cornell University€¦ · CourseGoals • Learntechniquesformodelingprograms∗ I Formalsemantics(operational,axiomatic,denotational) I Extendtoadvancedlanguagefeatures](https://reader033.vdocuments.pub/reader033/viewer/2022060518/604b93c2673ed862535917d5/html5/thumbnails/2.jpg)
Programming Languages
One of the oldest elds in Computer Science...• λ-calculus – Church (1936)• FORTRAN – Backus (1957)• LISP – McCarthy (1958)• ALGOL 60 – Backus, Naur, Perlis, & others (1960)• Pascal – Wirth (1970)• C – Ritchie (1972)• Smalltalk – Kay & others (1972)• ML – Milner and others (1978)• C++ – Stroustrup (1982)• Haskell – Hudak, Peyton Jones, Wadler, & others (1989)• Java – Gosling (1995)• C# – Microsoft (2001)• Scala – Odersky (2003)• F# – Syme (2005)
2
![Page 3: Lecture1 Introduction 24January2011 - Cornell University€¦ · CourseGoals • Learntechniquesformodelingprograms∗ I Formalsemantics(operational,axiomatic,denotational) I Extendtoadvancedlanguagefeatures](https://reader033.vdocuments.pub/reader033/viewer/2022060518/604b93c2673ed862535917d5/html5/thumbnails/3.jpg)
Programming Languages
...and one of the most vibrant areas today!
PL intersects with many other areas
Current trends
• Domain-speci c languages• Static analysis and types• Language-based security• Veri cation and model checking• Concurrency
Both theoretically and practically “meaty”
3
![Page 4: Lecture1 Introduction 24January2011 - Cornell University€¦ · CourseGoals • Learntechniquesformodelingprograms∗ I Formalsemantics(operational,axiomatic,denotational) I Extendtoadvancedlanguagefeatures](https://reader033.vdocuments.pub/reader033/viewer/2022060518/604b93c2673ed862535917d5/html5/thumbnails/4.jpg)
Syllabus
![Page 5: Lecture1 Introduction 24January2011 - Cornell University€¦ · CourseGoals • Learntechniquesformodelingprograms∗ I Formalsemantics(operational,axiomatic,denotational) I Extendtoadvancedlanguagefeatures](https://reader033.vdocuments.pub/reader033/viewer/2022060518/604b93c2673ed862535917d5/html5/thumbnails/5.jpg)
Course Goals
• Learn techniques for modeling programs∗
I Formal semantics (operational, axiomatic, denotational)I Extend to advanced language featuresI Develop reasoning principles (induction, co-induction)
• Explore applications of these techniquesI OptimizationI Static analysisI Veri cation
• PhD students: cover material for PL qualifying exam• Have fun :-)
*and whole languages!
5
![Page 6: Lecture1 Introduction 24January2011 - Cornell University€¦ · CourseGoals • Learntechniquesformodelingprograms∗ I Formalsemantics(operational,axiomatic,denotational) I Extendtoadvancedlanguagefeatures](https://reader033.vdocuments.pub/reader033/viewer/2022060518/604b93c2673ed862535917d5/html5/thumbnails/6.jpg)
.
.
.
. .
. Mathemetical Preliminaries &Operational Semantics
.Advanced Language Features
. Axiomatic & DenotationalSemantics
.Spring Break
.Preliminary Exam
.Types
.Advanced Types
.Study Period.Final Exam
. .
6
![Page 7: Lecture1 Introduction 24January2011 - Cornell University€¦ · CourseGoals • Learntechniquesformodelingprograms∗ I Formalsemantics(operational,axiomatic,denotational) I Extendtoadvancedlanguagefeatures](https://reader033.vdocuments.pub/reader033/viewer/2022060518/604b93c2673ed862535917d5/html5/thumbnails/7.jpg)
.
.
.
. .
. Mathemetical Preliminaries &Operational Semantics
.Advanced Language Features
. Axiomatic & DenotationalSemantics
.Spring Break
.Preliminary Exam
.Types
.Advanced Types
.Study Period.Final Exam
. .
6
![Page 8: Lecture1 Introduction 24January2011 - Cornell University€¦ · CourseGoals • Learntechniquesformodelingprograms∗ I Formalsemantics(operational,axiomatic,denotational) I Extendtoadvancedlanguagefeatures](https://reader033.vdocuments.pub/reader033/viewer/2022060518/604b93c2673ed862535917d5/html5/thumbnails/8.jpg)
.
.
.
. .
. Mathemetical Preliminaries &Operational Semantics
.Advanced Language Features
. Axiomatic & DenotationalSemantics
.Spring Break
.Preliminary Exam
.Types
.Advanced Types
.Study Period.Final Exam
. .
6
![Page 9: Lecture1 Introduction 24January2011 - Cornell University€¦ · CourseGoals • Learntechniquesformodelingprograms∗ I Formalsemantics(operational,axiomatic,denotational) I Extendtoadvancedlanguagefeatures](https://reader033.vdocuments.pub/reader033/viewer/2022060518/604b93c2673ed862535917d5/html5/thumbnails/9.jpg)
.
.
.
. .
. Mathemetical Preliminaries &Operational Semantics
.Advanced Language Features
. Axiomatic & DenotationalSemantics
.Spring Break
.Preliminary Exam
.Types
.Advanced Types
.Study Period.Final Exam
. .
6
![Page 10: Lecture1 Introduction 24January2011 - Cornell University€¦ · CourseGoals • Learntechniquesformodelingprograms∗ I Formalsemantics(operational,axiomatic,denotational) I Extendtoadvancedlanguagefeatures](https://reader033.vdocuments.pub/reader033/viewer/2022060518/604b93c2673ed862535917d5/html5/thumbnails/10.jpg)
.
.
.
. .
. Mathemetical Preliminaries &Operational Semantics
.Advanced Language Features
. Axiomatic & DenotationalSemantics
.Spring Break
.Preliminary Exam
.Types
.Advanced Types
.Study Period.Final Exam
. .
6
![Page 11: Lecture1 Introduction 24January2011 - Cornell University€¦ · CourseGoals • Learntechniquesformodelingprograms∗ I Formalsemantics(operational,axiomatic,denotational) I Extendtoadvancedlanguagefeatures](https://reader033.vdocuments.pub/reader033/viewer/2022060518/604b93c2673ed862535917d5/html5/thumbnails/11.jpg)
.
.
.
. .
. Mathemetical Preliminaries &Operational Semantics
.Advanced Language Features
. Axiomatic & DenotationalSemantics
.Spring Break
.Preliminary Exam
.Types
.Advanced Types
.Study Period.Final Exam
. .
6
![Page 12: Lecture1 Introduction 24January2011 - Cornell University€¦ · CourseGoals • Learntechniquesformodelingprograms∗ I Formalsemantics(operational,axiomatic,denotational) I Extendtoadvancedlanguagefeatures](https://reader033.vdocuments.pub/reader033/viewer/2022060518/604b93c2673ed862535917d5/html5/thumbnails/12.jpg)
.
.
.
. .
. Mathemetical Preliminaries &Operational Semantics
.Advanced Language Features
. Axiomatic & DenotationalSemantics
.Spring Break
.Preliminary Exam
.Types
.Advanced Types
.Study Period.Final Exam
. .
6
![Page 13: Lecture1 Introduction 24January2011 - Cornell University€¦ · CourseGoals • Learntechniquesformodelingprograms∗ I Formalsemantics(operational,axiomatic,denotational) I Extendtoadvancedlanguagefeatures](https://reader033.vdocuments.pub/reader033/viewer/2022060518/604b93c2673ed862535917d5/html5/thumbnails/13.jpg)
.
.
.
. .
. Mathemetical Preliminaries &Operational Semantics
.Advanced Language Features
. Axiomatic & DenotationalSemantics
.Spring Break
.Preliminary Exam
.Types
.Advanced Types
.Study Period.Final Exam
. .
6
![Page 14: Lecture1 Introduction 24January2011 - Cornell University€¦ · CourseGoals • Learntechniquesformodelingprograms∗ I Formalsemantics(operational,axiomatic,denotational) I Extendtoadvancedlanguagefeatures](https://reader033.vdocuments.pub/reader033/viewer/2022060518/604b93c2673ed862535917d5/html5/thumbnails/14.jpg)
.
.
.
. .
. Mathemetical Preliminaries &Operational Semantics
.Advanced Language Features
. Axiomatic & DenotationalSemantics
.Spring Break
.Preliminary Exam
.Types
.Advanced Types
.Study Period.Final Exam
. .
6
![Page 15: Lecture1 Introduction 24January2011 - Cornell University€¦ · CourseGoals • Learntechniquesformodelingprograms∗ I Formalsemantics(operational,axiomatic,denotational) I Extendtoadvancedlanguagefeatures](https://reader033.vdocuments.pub/reader033/viewer/2022060518/604b93c2673ed862535917d5/html5/thumbnails/15.jpg)
.
.
.
. .
. Mathemetical Preliminaries &Operational Semantics
.Advanced Language Features
. Axiomatic & DenotationalSemantics
.Spring Break
.Preliminary Exam
.Types
.Advanced Types
.Study Period.Final Exam
.
.
6
![Page 16: Lecture1 Introduction 24January2011 - Cornell University€¦ · CourseGoals • Learntechniquesformodelingprograms∗ I Formalsemantics(operational,axiomatic,denotational) I Extendtoadvancedlanguagefeatures](https://reader033.vdocuments.pub/reader033/viewer/2022060518/604b93c2673ed862535917d5/html5/thumbnails/16.jpg)
.
.
.
. .
. Mathemetical Preliminaries &Operational Semantics
.Advanced Language Features
. Axiomatic & DenotationalSemantics
.Spring Break
.Preliminary Exam
.Types
.Advanced Types
.Study Period.Final Exam
. .
6
![Page 17: Lecture1 Introduction 24January2011 - Cornell University€¦ · CourseGoals • Learntechniquesformodelingprograms∗ I Formalsemantics(operational,axiomatic,denotational) I Extendtoadvancedlanguagefeatures](https://reader033.vdocuments.pub/reader033/viewer/2022060518/604b93c2673ed862535917d5/html5/thumbnails/17.jpg)
Prerequisites
Programming Experience
• e.g., C, Java, Prolog, OCaml, Haskell, Scheme/Racket• Comfortable with a functional language• For undergrads: CS 3110 or 4110 or equivalent
Mathematical Maturity
• e.g., set theory, rigorous proofs, induction• Much of this class will involve formal reasoning• Hardest topic: denotational semantics
Interest (having fun is a goal! :-)
If you don’t meet these prerequisites, get in touch.
7
![Page 18: Lecture1 Introduction 24January2011 - Cornell University€¦ · CourseGoals • Learntechniquesformodelingprograms∗ I Formalsemantics(operational,axiomatic,denotational) I Extendtoadvancedlanguagefeatures](https://reader033.vdocuments.pub/reader033/viewer/2022060518/604b93c2673ed862535917d5/html5/thumbnails/18.jpg)
Course Work
Participation (5%)• Lectures, recitations, and of ce hours• Email list discussions
Homework (25%)• 6 assignments, roughly every other week• Mostly theoretical, some programming• Must work in groups of 2-3
Preliminary Exam (30%)• Wednesday, March 30th + take-home problems.
Final Exam (40%)• Friday, May 13th, 2pm-4:30pm• Cumulative, with focus on the material from 2nd half
8
![Page 19: Lecture1 Introduction 24January2011 - Cornell University€¦ · CourseGoals • Learntechniquesformodelingprograms∗ I Formalsemantics(operational,axiomatic,denotational) I Extendtoadvancedlanguagefeatures](https://reader033.vdocuments.pub/reader033/viewer/2022060518/604b93c2673ed862535917d5/html5/thumbnails/19.jpg)
Academic Integrity
Two simple requests:
1. Most of you are here training to become members ofthe research community. Conduct yourself withintegrity.
2. If you aren’t sure what is allowed and what isn’t,please ask!
9
![Page 20: Lecture1 Introduction 24January2011 - Cornell University€¦ · CourseGoals • Learntechniquesformodelingprograms∗ I Formalsemantics(operational,axiomatic,denotational) I Extendtoadvancedlanguagefeatures](https://reader033.vdocuments.pub/reader033/viewer/2022060518/604b93c2673ed862535917d5/html5/thumbnails/20.jpg)
Special Needs and Wellness
• I will provide reasonable accommodations to studentswho have a documented disability (e.g., physical,learning, psychiatric, vision, hearing, or systemic).
• If you are experiencing undue personal or academicstress at any time during the semester (or if you noticethat a fellow student is), contact me, EngineeringAdvising, or Gannett.
10
![Page 21: Lecture1 Introduction 24January2011 - Cornell University€¦ · CourseGoals • Learntechniquesformodelingprograms∗ I Formalsemantics(operational,axiomatic,denotational) I Extendtoadvancedlanguagefeatures](https://reader033.vdocuments.pub/reader033/viewer/2022060518/604b93c2673ed862535917d5/html5/thumbnails/21.jpg)
Course Staff
InstructorNate FosterOf ce: Upson 4137Hours: Wed 11am-12pm
Teaching AssistantJean-Baptiste JeanninOf ce: Upson 4142Hours: Tue 4:45pm-5:45pm and Thu 7pm-8pm
(of ce hours start next week)
Web Pagehttp://www.cs.cornell.edu/Courses/cs6110/2011sp
Mailing Listhttp://lists.semantics-is-gorges.org/listinfo/cs6110
11
![Page 22: Lecture1 Introduction 24January2011 - Cornell University€¦ · CourseGoals • Learntechniquesformodelingprograms∗ I Formalsemantics(operational,axiomatic,denotational) I Extendtoadvancedlanguagefeatures](https://reader033.vdocuments.pub/reader033/viewer/2022060518/604b93c2673ed862535917d5/html5/thumbnails/22.jpg)
Language Speci cation
![Page 23: Lecture1 Introduction 24January2011 - Cornell University€¦ · CourseGoals • Learntechniquesformodelingprograms∗ I Formalsemantics(operational,axiomatic,denotational) I Extendtoadvancedlanguagefeatures](https://reader033.vdocuments.pub/reader033/viewer/2022060518/604b93c2673ed862535917d5/html5/thumbnails/23.jpg)
Language Speci cation
Formal Semantics: what do programs mean?
Three Approaches
• OperationalI Models program by its execution on abstract machineI Useful for implementing compilers and interpreters
• AxiomaticI Models program by the logical formulas it obeysI Useful for proving program correctness
• DenotationalI Models program literally as mathematical objectsI Useful for theoretical foundations
Question: few languages have a formal semantics. Why?
13
![Page 24: Lecture1 Introduction 24January2011 - Cornell University€¦ · CourseGoals • Learntechniquesformodelingprograms∗ I Formalsemantics(operational,axiomatic,denotational) I Extendtoadvancedlanguagefeatures](https://reader033.vdocuments.pub/reader033/viewer/2022060518/604b93c2673ed862535917d5/html5/thumbnails/24.jpg)
Language Speci cation
Formal Semantics: what do programs mean?
Three Approaches
• OperationalI Models program by its execution on abstract machineI Useful for implementing compilers and interpreters
• AxiomaticI Models program by the logical formulas it obeysI Useful for proving program correctness
• DenotationalI Models program literally as mathematical objectsI Useful for theoretical foundations
Question: few languages have a formal semantics. Why?
13
![Page 25: Lecture1 Introduction 24January2011 - Cornell University€¦ · CourseGoals • Learntechniquesformodelingprograms∗ I Formalsemantics(operational,axiomatic,denotational) I Extendtoadvancedlanguagefeatures](https://reader033.vdocuments.pub/reader033/viewer/2022060518/604b93c2673ed862535917d5/html5/thumbnails/25.jpg)
Formal Semantics
Too Hard?
• Modeling a real-world language is hard• Notation can gets very dense• Sometimes requires developing new mathematics• Not yet cost-effective for everyday use
Overly General?
• Explains the behavior of a program on every input• Most programmers are content knowing the behaviorof their program on this input (or these inputs)
Okay, so who needs semantics?
14
![Page 26: Lecture1 Introduction 24January2011 - Cornell University€¦ · CourseGoals • Learntechniquesformodelingprograms∗ I Formalsemantics(operational,axiomatic,denotational) I Extendtoadvancedlanguagefeatures](https://reader033.vdocuments.pub/reader033/viewer/2022060518/604b93c2673ed862535917d5/html5/thumbnails/26.jpg)
A Tricky Example
Question #1: is the following Java program legal?
Question #2: if yes, what does it do?
..class A { static int a = B.b + 1; }
class B { static int b = A.a + 1; }
15
![Page 27: Lecture1 Introduction 24January2011 - Cornell University€¦ · CourseGoals • Learntechniquesformodelingprograms∗ I Formalsemantics(operational,axiomatic,denotational) I Extendtoadvancedlanguagefeatures](https://reader033.vdocuments.pub/reader033/viewer/2022060518/604b93c2673ed862535917d5/html5/thumbnails/27.jpg)
Who Needs Semantics?
Unambiguous Description
• Anyone who wants to design a new feature• Basis for most formal arguments• Standard tool in PL research
Exhaustive Reasoning
• Sometimes have to know behavior on all inputs• Compilers and interpreters• Static analysis tools• Program transformation tools• Critical software
16
![Page 28: Lecture1 Introduction 24January2011 - Cornell University€¦ · CourseGoals • Learntechniquesformodelingprograms∗ I Formalsemantics(operational,axiomatic,denotational) I Extendtoadvancedlanguagefeatures](https://reader033.vdocuments.pub/reader033/viewer/2022060518/604b93c2673ed862535917d5/html5/thumbnails/28.jpg)
Language Design
![Page 29: Lecture1 Introduction 24January2011 - Cornell University€¦ · CourseGoals • Learntechniquesformodelingprograms∗ I Formalsemantics(operational,axiomatic,denotational) I Extendtoadvancedlanguagefeatures](https://reader033.vdocuments.pub/reader033/viewer/2022060518/604b93c2673ed862535917d5/html5/thumbnails/29.jpg)
Design Desiderata
Question: What makes a good programming language?
One answer: “a good language is one people use”
Wrong! Are COBOL and JavaScript the best languages?
Some good features:
• Simplicity (clean, orthogonal constructs)• Readability (elegant syntax)• Safety (guarantees that programs won’t “go wrong”)• Support for programming in the large (modularity)• Ef ciency (good execution model and tools)
18
![Page 30: Lecture1 Introduction 24January2011 - Cornell University€¦ · CourseGoals • Learntechniquesformodelingprograms∗ I Formalsemantics(operational,axiomatic,denotational) I Extendtoadvancedlanguagefeatures](https://reader033.vdocuments.pub/reader033/viewer/2022060518/604b93c2673ed862535917d5/html5/thumbnails/30.jpg)
Design Desiderata
Question: What makes a good programming language?
One answer: “a good language is one people use”
Wrong! Are COBOL and JavaScript the best languages?
Some good features:
• Simplicity (clean, orthogonal constructs)• Readability (elegant syntax)• Safety (guarantees that programs won’t “go wrong”)• Support for programming in the large (modularity)• Ef ciency (good execution model and tools)
18
![Page 31: Lecture1 Introduction 24January2011 - Cornell University€¦ · CourseGoals • Learntechniquesformodelingprograms∗ I Formalsemantics(operational,axiomatic,denotational) I Extendtoadvancedlanguagefeatures](https://reader033.vdocuments.pub/reader033/viewer/2022060518/604b93c2673ed862535917d5/html5/thumbnails/31.jpg)
Design Desiderata
Question: What makes a good programming language?
One answer: “a good language is one people use”
Wrong! Are COBOL and JavaScript the best languages?
Some good features:
• Simplicity (clean, orthogonal constructs)• Readability (elegant syntax)• Safety (guarantees that programs won’t “go wrong”)• Support for programming in the large (modularity)• Ef ciency (good execution model and tools)
18
![Page 32: Lecture1 Introduction 24January2011 - Cornell University€¦ · CourseGoals • Learntechniquesformodelingprograms∗ I Formalsemantics(operational,axiomatic,denotational) I Extendtoadvancedlanguagefeatures](https://reader033.vdocuments.pub/reader033/viewer/2022060518/604b93c2673ed862535917d5/html5/thumbnails/32.jpg)
Design Desiderata
Question: What makes a good programming language?
One answer: “a good language is one people use”
Wrong! Are COBOL and JavaScript the best languages?
Some good features:
• Simplicity (clean, orthogonal constructs)• Readability (elegant syntax)• Safety (guarantees that programs won’t “go wrong”)• Support for programming in the large (modularity)• Ef ciency (good execution model and tools)
18
![Page 33: Lecture1 Introduction 24January2011 - Cornell University€¦ · CourseGoals • Learntechniquesformodelingprograms∗ I Formalsemantics(operational,axiomatic,denotational) I Extendtoadvancedlanguagefeatures](https://reader033.vdocuments.pub/reader033/viewer/2022060518/604b93c2673ed862535917d5/html5/thumbnails/33.jpg)
Design Challenges
Unfortunately these goals almost always con ict
• Types restrict expressiveness in general, but theyprovide strong guarantees
• Safety checks eliminate errors but have a cost, eitherwhen compiling or when the program is executed
• Some veri cation tools are so complicated, oneessentially needs a PhD to use them
A lot of PL research is about nding ways to gainwithout too much pain
19
![Page 34: Lecture1 Introduction 24January2011 - Cornell University€¦ · CourseGoals • Learntechniquesformodelingprograms∗ I Formalsemantics(operational,axiomatic,denotational) I Extendtoadvancedlanguagefeatures](https://reader033.vdocuments.pub/reader033/viewer/2022060518/604b93c2673ed862535917d5/html5/thumbnails/34.jpg)
Design Challenges
Unfortunately these goals almost always con ict
• Types restrict expressiveness in general, but theyprovide strong guarantees
• Safety checks eliminate errors but have a cost, eitherwhen compiling or when the program is executed
• Some veri cation tools are so complicated, oneessentially needs a PhD to use them
A lot of PL research is about nding ways to gainwithout too much pain
19
![Page 35: Lecture1 Introduction 24January2011 - Cornell University€¦ · CourseGoals • Learntechniquesformodelingprograms∗ I Formalsemantics(operational,axiomatic,denotational) I Extendtoadvancedlanguagefeatures](https://reader033.vdocuments.pub/reader033/viewer/2022060518/604b93c2673ed862535917d5/html5/thumbnails/35.jpg)
Story: Unexpected Interactions
A real story illustrating the perils of language design
Cast of characters includes famous computer scientists
Timeline:
• 1982: ML is a functional language with type inference,polymorphism (generics), and monomorphicreferences (pointers)
• 1985: Standard ML innovates by adding polymorphicreferences → unsoundness
• 1995: The “innovation” xed
20
![Page 36: Lecture1 Introduction 24January2011 - Cornell University€¦ · CourseGoals • Learntechniquesformodelingprograms∗ I Formalsemantics(operational,axiomatic,denotational) I Extendtoadvancedlanguagefeatures](https://reader033.vdocuments.pub/reader033/viewer/2022060518/604b93c2673ed862535917d5/html5/thumbnails/36.jpg)
ML Type System
Polymorphism: allows code to be used at different types
Examples:
• List.length : ∀α. α list → int• List.hd : ∀α. α list → α
Type Inference: e τ
• e.g., let id (x) = x ∀α. α → α
• Generalize types not constrainted by the program• Instantiate types at use id (true) bool
21
![Page 37: Lecture1 Introduction 24January2011 - Cornell University€¦ · CourseGoals • Learntechniquesformodelingprograms∗ I Formalsemantics(operational,axiomatic,denotational) I Extendtoadvancedlanguagefeatures](https://reader033.vdocuments.pub/reader033/viewer/2022060518/604b93c2673ed862535917d5/html5/thumbnails/37.jpg)
ML References
By default, values in ML are immutable.
But can extend the language with imperative features.
Add reference types of the form τ ref
Add expressions of the form
• ref e : τ ref where e : τ (allocate)• !e : τ where e : τ ref (dereference)• e1 := e2 : unit where e1 : τ ref and e2 : τ (assign)
Works as you’d expect—i.e., just like pointers in C
22
![Page 38: Lecture1 Introduction 24January2011 - Cornell University€¦ · CourseGoals • Learntechniquesformodelingprograms∗ I Formalsemantics(operational,axiomatic,denotational) I Extendtoadvancedlanguagefeatures](https://reader033.vdocuments.pub/reader033/viewer/2022060518/604b93c2673ed862535917d5/html5/thumbnails/38.jpg)
Polymorphism + References
Consider the following program
..
Code Inferred Type
let id(x) = x id : ∀α α → α
let p = ref id p : ∀α (α → α) ref
let inc(n) = n+1 inc : int → int
let () = p := inc OK since p : (int → int) ref
(!p) true OK since p : (bool → bool) ref
23
![Page 39: Lecture1 Introduction 24January2011 - Cornell University€¦ · CourseGoals • Learntechniquesformodelingprograms∗ I Formalsemantics(operational,axiomatic,denotational) I Extendtoadvancedlanguagefeatures](https://reader033.vdocuments.pub/reader033/viewer/2022060518/604b93c2673ed862535917d5/html5/thumbnails/39.jpg)
Polymorphism + References
Consider the following program
..
Code Inferred Type
let id(x) = x id : ∀α α → α
let p = ref id p : ∀α (α → α) ref
let inc(n) = n+1 inc : int → int
let () = p := inc OK since p : (int → int) ref
(!p) true OK since p : (bool → bool) ref
23
![Page 40: Lecture1 Introduction 24January2011 - Cornell University€¦ · CourseGoals • Learntechniquesformodelingprograms∗ I Formalsemantics(operational,axiomatic,denotational) I Extendtoadvancedlanguagefeatures](https://reader033.vdocuments.pub/reader033/viewer/2022060518/604b93c2673ed862535917d5/html5/thumbnails/40.jpg)
Polymorphism + References
Consider the following program
..
Code Inferred Type
let id(x) = x id : ∀α α → α
let p = ref id p : ∀α (α → α) ref
let inc(n) = n+1 inc : int → int
let () = p := inc OK since p : (int → int) ref
(!p) true OK since p : (bool → bool) ref
23
![Page 41: Lecture1 Introduction 24January2011 - Cornell University€¦ · CourseGoals • Learntechniquesformodelingprograms∗ I Formalsemantics(operational,axiomatic,denotational) I Extendtoadvancedlanguagefeatures](https://reader033.vdocuments.pub/reader033/viewer/2022060518/604b93c2673ed862535917d5/html5/thumbnails/41.jpg)
Polymorphism + References
Consider the following program
..
Code Inferred Type
let id(x) = x id : ∀α α → α
let p = ref id p : ∀α (α → α) ref
let inc(n) = n+1 inc : int → int
let () = p := inc OK since p : (int → int) ref
(!p) true OK since p : (bool → bool) ref
23
![Page 42: Lecture1 Introduction 24January2011 - Cornell University€¦ · CourseGoals • Learntechniquesformodelingprograms∗ I Formalsemantics(operational,axiomatic,denotational) I Extendtoadvancedlanguagefeatures](https://reader033.vdocuments.pub/reader033/viewer/2022060518/604b93c2673ed862535917d5/html5/thumbnails/42.jpg)
Polymorphism + References
Consider the following program
..
Code Inferred Type
let id(x) = x id : ∀α α → α
let p = ref id p : ∀α (α → α) ref
let inc(n) = n+1 inc : int → int
let () = p := inc OK since p : (int → int) ref
(!p) true OK since p : (bool → bool) ref
23
![Page 43: Lecture1 Introduction 24January2011 - Cornell University€¦ · CourseGoals • Learntechniquesformodelingprograms∗ I Formalsemantics(operational,axiomatic,denotational) I Extendtoadvancedlanguagefeatures](https://reader033.vdocuments.pub/reader033/viewer/2022060518/604b93c2673ed862535917d5/html5/thumbnails/43.jpg)
Polymorphism + References
Problem
• Type system is not sound• Well-typed program →∗ type error!
Proposed Solutions
1. “Weak” type variablesI Can only be instantiated in restricted waysI But type exposes functional vs. imperativeI Somewhat dif cult to use
2. Value restrictionI Only generalize types of valuesI Most ML programs already obey itI Simple proof of type soundness
24
![Page 44: Lecture1 Introduction 24January2011 - Cornell University€¦ · CourseGoals • Learntechniquesformodelingprograms∗ I Formalsemantics(operational,axiomatic,denotational) I Extendtoadvancedlanguagefeatures](https://reader033.vdocuments.pub/reader033/viewer/2022060518/604b93c2673ed862535917d5/html5/thumbnails/44.jpg)
Polymorphism + References
Problem
• Type system is not sound• Well-typed program →∗ type error!
Proposed Solutions
1. “Weak” type variablesI Can only be instantiated in restricted waysI But type exposes functional vs. imperativeI Somewhat dif cult to use
2. Value restrictionI Only generalize types of valuesI Most ML programs already obey itI Simple proof of type soundness
24
![Page 45: Lecture1 Introduction 24January2011 - Cornell University€¦ · CourseGoals • Learntechniquesformodelingprograms∗ I Formalsemantics(operational,axiomatic,denotational) I Extendtoadvancedlanguagefeatures](https://reader033.vdocuments.pub/reader033/viewer/2022060518/604b93c2673ed862535917d5/html5/thumbnails/45.jpg)
Polymorphism + References
Problem
• Type system is not sound• Well-typed program →∗ type error!
Proposed Solutions
1. “Weak” type variablesI Can only be instantiated in restricted waysI But type exposes functional vs. imperativeI Somewhat dif cult to use
2. Value restrictionI Only generalize types of valuesI Most ML programs already obey itI Simple proof of type soundness
24
![Page 46: Lecture1 Introduction 24January2011 - Cornell University€¦ · CourseGoals • Learntechniquesformodelingprograms∗ I Formalsemantics(operational,axiomatic,denotational) I Extendtoadvancedlanguagefeatures](https://reader033.vdocuments.pub/reader033/viewer/2022060518/604b93c2673ed862535917d5/html5/thumbnails/46.jpg)
Lessons Learned
• Features often interact in unexpected ways
• The design space is huge
• Good designs are sparse → don’t happen by accident
• Simplicity is rare: n features lead to n2 interactions
• Most PL researchers work with really small languages(e.g., λ-calculus) to study core issues in isolation
• But must pay attention to whole languages too
25
![Page 47: Lecture1 Introduction 24January2011 - Cornell University€¦ · CourseGoals • Learntechniquesformodelingprograms∗ I Formalsemantics(operational,axiomatic,denotational) I Extendtoadvancedlanguagefeatures](https://reader033.vdocuments.pub/reader033/viewer/2022060518/604b93c2673ed862535917d5/html5/thumbnails/47.jpg)
Mathematical Preliminaries
![Page 48: Lecture1 Introduction 24January2011 - Cornell University€¦ · CourseGoals • Learntechniquesformodelingprograms∗ I Formalsemantics(operational,axiomatic,denotational) I Extendtoadvancedlanguagefeatures](https://reader033.vdocuments.pub/reader033/viewer/2022060518/604b93c2673ed862535917d5/html5/thumbnails/48.jpg)
Binary Relations
The product of two sets A and B, written A× B, containsall ordered pairs (a,b) with a ∈ A and b ∈ B.
A binary relation on A and B is just a subset R ⊆ A× B.
Given a binary relation R ⊆ A× B, the set A is called thedomain of R and B is called the range (or codomain) of R.
Some Important Relations
• empty – ∅• total – A× B• identity on A – {(a, a) | a ∈ A}.• composition R; S – {(a, c) | ∃b. (a,b) ∈ R ∧ (b, c) ∈ S}
27
![Page 49: Lecture1 Introduction 24January2011 - Cornell University€¦ · CourseGoals • Learntechniquesformodelingprograms∗ I Formalsemantics(operational,axiomatic,denotational) I Extendtoadvancedlanguagefeatures](https://reader033.vdocuments.pub/reader033/viewer/2022060518/604b93c2673ed862535917d5/html5/thumbnails/49.jpg)
Binary Relations
The product of two sets A and B, written A× B, containsall ordered pairs (a,b) with a ∈ A and b ∈ B.
A binary relation on A and B is just a subset R ⊆ A× B.
Given a binary relation R ⊆ A× B, the set A is called thedomain of R and B is called the range (or codomain) of R.
Some Important Relations
• empty – ∅• total – A× B• identity on A – {(a, a) | a ∈ A}.• composition R; S – {(a, c) | ∃b. (a,b) ∈ R ∧ (b, c) ∈ S}
27
![Page 50: Lecture1 Introduction 24January2011 - Cornell University€¦ · CourseGoals • Learntechniquesformodelingprograms∗ I Formalsemantics(operational,axiomatic,denotational) I Extendtoadvancedlanguagefeatures](https://reader033.vdocuments.pub/reader033/viewer/2022060518/604b93c2673ed862535917d5/html5/thumbnails/50.jpg)
Binary Relations
The product of two sets A and B, written A× B, containsall ordered pairs (a,b) with a ∈ A and b ∈ B.
A binary relation on A and B is just a subset R ⊆ A× B.
Given a binary relation R ⊆ A× B, the set A is called thedomain of R and B is called the range (or codomain) of R.
Some Important Relations
• empty – ∅• total – A× B• identity on A – {(a, a) | a ∈ A}.• composition R; S – {(a, c) | ∃b. (a,b) ∈ R ∧ (b, c) ∈ S}
27
![Page 51: Lecture1 Introduction 24January2011 - Cornell University€¦ · CourseGoals • Learntechniquesformodelingprograms∗ I Formalsemantics(operational,axiomatic,denotational) I Extendtoadvancedlanguagefeatures](https://reader033.vdocuments.pub/reader033/viewer/2022060518/604b93c2673ed862535917d5/html5/thumbnails/51.jpg)
Binary Relations
The product of two sets A and B, written A× B, containsall ordered pairs (a,b) with a ∈ A and b ∈ B.
A binary relation on A and B is just a subset R ⊆ A× B.
Given a binary relation R ⊆ A× B, the set A is called thedomain of R and B is called the range (or codomain) of R.
Some Important Relations
• empty – ∅• total – A× B• identity on A – {(a, a) | a ∈ A}.• composition R; S – {(a, c) | ∃b. (a,b) ∈ R ∧ (b, c) ∈ S}
27
![Page 52: Lecture1 Introduction 24January2011 - Cornell University€¦ · CourseGoals • Learntechniquesformodelingprograms∗ I Formalsemantics(operational,axiomatic,denotational) I Extendtoadvancedlanguagefeatures](https://reader033.vdocuments.pub/reader033/viewer/2022060518/604b93c2673ed862535917d5/html5/thumbnails/52.jpg)
Functions
A (total) function f is a binary relation f ⊆ A× B with theproperty that every a ∈ A is related to exactly one b ∈ B.
When f is a function, we usually write f : A → B insteadof f ⊆ A× B.
The domain and range of f are de ned in exactly thesame way as for relations.
The image of f is the set of elements b ∈ B that aremapped to by at least one a ∈ A:
{f(a) | a ∈ A}
28
![Page 53: Lecture1 Introduction 24January2011 - Cornell University€¦ · CourseGoals • Learntechniquesformodelingprograms∗ I Formalsemantics(operational,axiomatic,denotational) I Extendtoadvancedlanguagefeatures](https://reader033.vdocuments.pub/reader033/viewer/2022060518/604b93c2673ed862535917d5/html5/thumbnails/53.jpg)
Functions
A (total) function f is a binary relation f ⊆ A× B with theproperty that every a ∈ A is related to exactly one b ∈ B.
When f is a function, we usually write f : A → B insteadof f ⊆ A× B.
The domain and range of f are de ned in exactly thesame way as for relations.
The image of f is the set of elements b ∈ B that aremapped to by at least one a ∈ A:
{f(a) | a ∈ A}
28
![Page 54: Lecture1 Introduction 24January2011 - Cornell University€¦ · CourseGoals • Learntechniquesformodelingprograms∗ I Formalsemantics(operational,axiomatic,denotational) I Extendtoadvancedlanguagefeatures](https://reader033.vdocuments.pub/reader033/viewer/2022060518/604b93c2673ed862535917d5/html5/thumbnails/54.jpg)
Functions
A (total) function f is a binary relation f ⊆ A× B with theproperty that every a ∈ A is related to exactly one b ∈ B.
When f is a function, we usually write f : A → B insteadof f ⊆ A× B.
The domain and range of f are de ned in exactly thesame way as for relations.
The image of f is the set of elements b ∈ B that aremapped to by at least one a ∈ A:
{f(a) | a ∈ A}
28
![Page 55: Lecture1 Introduction 24January2011 - Cornell University€¦ · CourseGoals • Learntechniquesformodelingprograms∗ I Formalsemantics(operational,axiomatic,denotational) I Extendtoadvancedlanguagefeatures](https://reader033.vdocuments.pub/reader033/viewer/2022060518/604b93c2673ed862535917d5/html5/thumbnails/55.jpg)
Functions
A (total) function f is a binary relation f ⊆ A× B with theproperty that every a ∈ A is related to exactly one b ∈ B.
When f is a function, we usually write f : A → B insteadof f ⊆ A× B.
The domain and range of f are de ned in exactly thesame way as for relations.
The image of f is the set of elements b ∈ B that aremapped to by at least one a ∈ A:
{f(a) | a ∈ A}
28
![Page 56: Lecture1 Introduction 24January2011 - Cornell University€¦ · CourseGoals • Learntechniquesformodelingprograms∗ I Formalsemantics(operational,axiomatic,denotational) I Extendtoadvancedlanguagefeatures](https://reader033.vdocuments.pub/reader033/viewer/2022060518/604b93c2673ed862535917d5/html5/thumbnails/56.jpg)
Some Important Functions
Given two functions f : A → B and g : B → C, thecomposition of f and g is de ned by:
(g ◦ f)(x) = g(f(x)) Note order!
A partial function f : A ⇀ B is a total function f : A′ → Bon a set A′ ⊆ A. The notation dom(f) refers to A′.
A function f : A → B is said to be injective (or one-to-one)if and only if a1 ̸= a2 implies f(a1) ̸= f(a2).
A function f : A → B is said to be surjective (or onto) ifand only if the image of f is B.
29
![Page 57: Lecture1 Introduction 24January2011 - Cornell University€¦ · CourseGoals • Learntechniquesformodelingprograms∗ I Formalsemantics(operational,axiomatic,denotational) I Extendtoadvancedlanguagefeatures](https://reader033.vdocuments.pub/reader033/viewer/2022060518/604b93c2673ed862535917d5/html5/thumbnails/57.jpg)
Some Important Functions
Given two functions f : A → B and g : B → C, thecomposition of f and g is de ned by:
(g ◦ f)(x) = g(f(x)) Note order!
A partial function f : A ⇀ B is a total function f : A′ → Bon a set A′ ⊆ A. The notation dom(f) refers to A′.
A function f : A → B is said to be injective (or one-to-one)if and only if a1 ̸= a2 implies f(a1) ̸= f(a2).
A function f : A → B is said to be surjective (or onto) ifand only if the image of f is B.
29
![Page 58: Lecture1 Introduction 24January2011 - Cornell University€¦ · CourseGoals • Learntechniquesformodelingprograms∗ I Formalsemantics(operational,axiomatic,denotational) I Extendtoadvancedlanguagefeatures](https://reader033.vdocuments.pub/reader033/viewer/2022060518/604b93c2673ed862535917d5/html5/thumbnails/58.jpg)
Some Important Functions
Given two functions f : A → B and g : B → C, thecomposition of f and g is de ned by:
(g ◦ f)(x) = g(f(x)) Note order!
A partial function f : A ⇀ B is a total function f : A′ → Bon a set A′ ⊆ A. The notation dom(f) refers to A′.
A function f : A → B is said to be injective (or one-to-one)if and only if a1 ̸= a2 implies f(a1) ̸= f(a2).
A function f : A → B is said to be surjective (or onto) ifand only if the image of f is B.
29
![Page 59: Lecture1 Introduction 24January2011 - Cornell University€¦ · CourseGoals • Learntechniquesformodelingprograms∗ I Formalsemantics(operational,axiomatic,denotational) I Extendtoadvancedlanguagefeatures](https://reader033.vdocuments.pub/reader033/viewer/2022060518/604b93c2673ed862535917d5/html5/thumbnails/59.jpg)
Some Important Functions
Given two functions f : A → B and g : B → C, thecomposition of f and g is de ned by:
(g ◦ f)(x) = g(f(x)) Note order!
A partial function f : A ⇀ B is a total function f : A′ → Bon a set A′ ⊆ A. The notation dom(f) refers to A′.
A function f : A → B is said to be injective (or one-to-one)if and only if a1 ̸= a2 implies f(a1) ̸= f(a2).
A function f : A → B is said to be surjective (or onto) ifand only if the image of f is B.
29
![Page 60: Lecture1 Introduction 24January2011 - Cornell University€¦ · CourseGoals • Learntechniquesformodelingprograms∗ I Formalsemantics(operational,axiomatic,denotational) I Extendtoadvancedlanguagefeatures](https://reader033.vdocuments.pub/reader033/viewer/2022060518/604b93c2673ed862535917d5/html5/thumbnails/60.jpg)
Extensions vs. Intensions
Mathematically, a function f is de ned by its extension:the set of pairs of inputs and outputs.
A function can also be described by an intensionalrepresentation: a program or procedure that computesan output given an input.
The same function can have several intensionalrepresentations—e.g., for the identity:
• λa.a• λa. if true then a else a• λa. if false then a else a
• λa. π1 (a,a)• λa. π2 (a,a)• λa. (λy. y) a
30
![Page 61: Lecture1 Introduction 24January2011 - Cornell University€¦ · CourseGoals • Learntechniquesformodelingprograms∗ I Formalsemantics(operational,axiomatic,denotational) I Extendtoadvancedlanguagefeatures](https://reader033.vdocuments.pub/reader033/viewer/2022060518/604b93c2673ed862535917d5/html5/thumbnails/61.jpg)
Extensions vs. Intensions
Mathematically, a function f is de ned by its extension:the set of pairs of inputs and outputs.
A function can also be described by an intensionalrepresentation: a program or procedure that computesan output given an input.
The same function can have several intensionalrepresentations—e.g., for the identity:
• λa.a• λa. if true then a else a• λa. if false then a else a
• λa. π1 (a,a)• λa. π2 (a,a)• λa. (λy. y) a
30