MinML: an idealized programming language CS 510 David Walker.

Slides:



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

Types and Programming Languages Lecture 7 Simon Gay Department of Computing Science University of Glasgow 2006/07.
Substitution & Evaluation Order cos 441 David Walker.
CSE341: Programming Languages Lecture 2 Functions, Pairs, Lists Dan Grossman Winter 2013.
- Vasvi Kakkad.  Formal -  Tool for mathematical analysis of language  Method for precisely designing language  Well formed model for describing and.
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.
Copyright © 2006 Addison-Wesley. All rights reserved.1-1 ICS 410: Programming Languages Chapter 3 : Describing Syntax and Semantics Axiomatic Semantics.
ISBN Chapter 3 Describing Syntax and Semantics.
1 Semantic Description of Programming languages. 2 Static versus Dynamic Semantics n Static Semantics represents legal forms of programs that cannot be.
CS 355 – Programming Languages
Comp 205: Comparative Programming Languages Semantics of Imperative Programming Languages denotational semantics operational semantics logical semantics.
Dr. Muhammed Al-Mulhem 1ICS ICS 535 Design and Implementation of Programming Languages Part 1 Fundamentals (Chapter 4) Operational Semantics ICS.
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.
Copyright © 2006 Addison-Wesley. All rights reserved.1-1 ICS 410: Programming Languages Chapter 3 : Describing Syntax and Semantics Operational Semantics.
Slides prepared by Rose Williams, Binghamton University Chapter 3 Flow of Control Loops in Java.
Programming Language Semantics Mooly SagivEran Yahav Schrirber 317Open space html://
©Ian Sommerville 2000Software Engineering, 6/e, Chapter 91 Formal Specification l Techniques for the unambiguous specification of software.
Semantics with Applications Mooly Sagiv Schrirber html:// Textbooks:Winskel The.
CS 330 Programming Languages 09 / 16 / 2008 Instructor: Michael Eckmann.
Semantics for MinML COS 441 Princeton University Fall 2004.
Describing Syntax and Semantics
©Ian Sommerville 2006Software Engineering, 8th edition. Chapter 10 Slide 1 Formal Specification.
CHAPTER 10 Recursion. 2 Recursive Thinking Recursion is a programming technique in which a method can call itself to solve a problem A recursive definition.
©Ian Sommerville 2000Software Engineering, 6th edition. Chapter 9 Slide 1 Formal Specification l Techniques for the unambiguous specification of software.
Advanced Programming Collage of Information Technology University of Palestine, Gaza Prepared by: Mahmoud Rafeek Alfarra Lecture 2: Major Concepts of Programming.
CSE S. Tanimoto Lambda Calculus 1 Lambda Calculus What is the simplest functional language that is still Turing complete? Where do functional languages.
Introduction Algorithms and Conventions The design and analysis of algorithms is the core subject matter of Computer Science. Given a problem, we want.
CPS120 Introduction to Computer Science Iteration (Looping)
Typed Lambda Calculus Chapter 9 Benjamin Pierce Types and Programming Languages.
WXGE6103 Software Engineering Process and Practice Formal Specification.
What does a computer program look like: a general overview.
ISBN Chapter 3 Describing Semantics -Attribute Grammars -Dynamic Semantics.
CS 363 Comparative Programming Languages Semantics.
Algorithms & FlowchartsLecture 10. Algorithm’s CONCEPT.
3.2 Semantics. 2 Semantics Attribute Grammars The Meanings of Programs: Semantics Sebesta Chapter 3.
Chapter 3 Part II Describing Syntax and Semantics.
Programming Languages and Design Lecture 3 Semantic Specifications of Programming Languages Instructor: Li Ma Department of Computer Science Texas Southern.
Semantics In Text: Chapter 3.
Syntax and Semantics CIS 331 Syntax: the form or structure of the expressions, statements, and program units. Semantics: the meaning of the expressions,
Formal Methods in Software Engineering Credit Hours: 3+0 By: Qaisar Javaid Assistant Professor.
Types and Programming Languages Lecture 12 Simon Gay Department of Computing Science University of Glasgow 2006/07.
12/9/20151 Programming Languages and Compilers (CS 421) Elsa L Gunter 2112 SC, UIUC Based in part on slides by Mattox.
CPS120 Introduction to Computer Science Iteration (Looping)
Advanced Formal Methods Lecture 3: Simply Typed Lambda calculus Mads Dam KTH/CSC Course 2D1453, Some material from B. Pierce: TAPL + some from.
Just Enough Type Theory or, Featherweight Java A Simple Formal Model of Objects Jonathan Aldrich
Types and Programming Languages Lecture 11 Simon Gay Department of Computing Science University of Glasgow 2006/07.
CMSC 330: Organization of Programming Languages Operational Semantics a.k.a. “WTF is Project 4, Part 3?”
CMSC 330: Organization of Programming Languages Lambda Calculus and Types.
Advanced Functional Programming Tim Sheard 1 Lecture 17 Advanced Functional Programming Tim Sheard Oregon Graduate Institute of Science & Technology Lecture:
Types and Programming Languages
CS412/413 Introduction to Compilers Radu Rugina Lecture 13 : Static Semantics 18 Feb 02.
The single most important skill for a computer programmer is problem solving Problem solving means the ability to formulate problems, think creatively.
CMSC 330: Organization of Programming Languages Operational Semantics.
Types and Programming Languages Lecture 3 Simon Gay Department of Computing Science University of Glasgow 2006/07.
CSC3315 (Spring 2009)1 CSC 3315 Languages & Compilers Hamid Harroud School of Science and Engineering, Akhawayn University
C HAPTER 3 Describing Syntax and Semantics. D YNAMIC S EMANTICS Describing syntax is relatively simple There is no single widely acceptable notation or.
Prof. Necula CS 164 Lecture 171 Operational Semantics of Cool ICOM 4029 Lecture 10.
Operational Semantics Mooly Sagiv Tel Aviv University Sunday Scrieber 8 Monday Schrieber.
CS5205Semantics1 CS5205: Foundation in Programming Languages Semantics Static Semantics Dynamic Semantics Operational Semantics Big-step Small-Step Denotational.
Chapter 1: Preliminaries Lecture # 2. Chapter 1: Preliminaries Reasons for Studying Concepts of Programming Languages Programming Domains Language Evaluation.
1 Interactive Computer Theorem Proving CS294-9 September 7, 2006 Adam Chlipala UC Berkeley Lecture 3: Data structures and Induction.
CS5205: Foundations in Programming Languages
Functional Programming
Formal Specification.
Programming Languages and Compilers (CS 421)
Topic: Programming Languages and their Evolution + Intro to Scratch
Algorithm Analysis CSE 2011 Winter September 2018.
Typed Arithmetic Expressions
PROGRAMMING IN HASKELL
This Lecture Substitution model
Presentation transcript:

MinML: an idealized programming language CS 510 David Walker

MinML Reading: –Pierce chapter 1, 9 the meaning of program safety the typed lambda calculus –Harper 5-8 MinML

MinML is an idealized programming language based on the lambda calculus the definition of MinML includes –a syntax for expressions involving recursive functions, booleans and integers –a dynamic semantics similar to the call-by- value semantics of lambda calculus –a set of typing rules to prevent programs from incurring certain sorts of errors

syntax types: t ::= int | bool | t1 -> t2 expressions: op ::= + | - | < |... e ::= x | n | b | e op e | if e then e else e | fun f (x:t):t = e | e e

syntax A simple example: fun fact (x : int ) : int = if x <= 0 then 1 else x * fact (x-1)

dynamic semantics As we did for the lambda calculus, we will define the dynamic semantics as a relation: e --> e’ but we have some choices to make...

dynamic semantics there are at least two general approaches: –by translation: describe execution by translating the language into some lower-level language we showed how to implement booleans, pairs in the lambda calculus by translating them into functions... –language-based: describe execution entirely in terms of language itself we showed how to implement functions in the lambda calculus directly

translation-based approach Advantages –clear implementation strategy in terms of lower-level concepts –sometimes simplifies complex language by translation into a smaller core that can be more easily understood –if translation to machine-level facilitates low-level programming (writing device drivers; interfacing with garbage collector) supports low-level “hacks” that depend upon specific machines

translation-based approach disadvantages –requires you understand how language is compiled problematic if compilation is complex –can prohibit portability and optimization –run-time errors cannot necessarily be understood in terms of the source program, only in terms of how it is compiled and executed

language-based models define execution entirely at the level of the language itself advantages –portable –(for the most part) do not need to introduce new concepts to explain execution –simpler explanation of errors

language-based models disadvantages –cannot take advantage of machine-specific details –does not to suggest a compilation strategy –can be more difficult to understand the time and space complexity

back to MinML dynamic semantics For MinML, we’re going to give the dynamic semantics directly We will use a relation with the form e1  e2 values: v ::= n | b | fix f (x:t1) : t2 = e

MinML dynamic semantics Primitive instructions: n1 + n2  n (when, mathematically, the sum of n1 and n2 is n) n = n  true n = n’  false (when n and n’ are different numbers) if true then e1 else e2  e1 if false then e1 else e2  e2

MinML dynamic semantics Primitive instructions: v1 v2  e [v1/f] [v2/x] (when v1 = fix f (x:t1) : t2 = e)

MinML dynamic semantics By the way, normally: – I write the side conditions inside the body of the rule –express them using mathematical notation rather than English examples: v1 v2  e [v1/f] [v2/x] (v1 = (fix f (x:t1) : t2 = e))(n = n1 + n2) n1 + n2  n (n ≠ n’) n = n’  false

MinML dynamic semantics Search rules –recall, these rules specify the order of evaluation –we’ll use left-to-right, call-by-value: e1  e1’ e1 op e2  e1’ op e2 e2  e2’ v1 op e2  v1 op e2’ e1  e1’ e1 e2  e1’ e2 e2  e2’ v1 e2  v1 e2’ e1  e1’ if e1 then e2 else e3  if e1’ then e2 else e3

MinML dynamic semantics once again, multi-step evaluation: e  * e e  e’ e’  * e’’ e  * e’’

some properties proposition 1 (values are irreducible) –if v is a value then there is no e such that v  e. Proof?

some properties proposition 1 (values are irreducible) –if v is a value then there is no e such that v  e. Proof? By inspection of the operational rules. There is no rule with the form: (To call this proof “inductive” is technically correct, but misleading: we do not appeal to the inductive hypothesis. We could also call it a proof “by case analysis of the operational rules”) premises v  e

some properties proposition 2 (determinacy) –for every e there is at most one e’ such that e  e’. Proof?

some properties proposition 2 (determinacy) –for every e there is at most one e’ such that e  e’. Proof? By induction on the structure of e. case (fix f (x : t1) : t2 = e). This is a value. By prop 1, there are no such e’. case...

some properties proposition 2 (determinacy) –for every e there is at most one e’ such that e  e’. Proof? By induction on the structure of e. case e1 e2: subcase e1, e2 both not values:... subcase e1 value, e2 not value:... subcase e1, e2 both values:...

some properties proposition 3 (determinacy of values) –for every e there is at most one v such that e  * v. Proof?

some properties proposition 3 (determinacy of values) –for every e there is at most one v such that e  * v. Proof? By induction on the multi-step relation + it helps to be more formal about the induction hypothesis: IH: If e  * v and e  * v’ then v = v’. Proof uses prop 1 & 2.

stuck states not every irreducible expression is a value: –if 7 then 1 else 2 –true + false –0 (17) an expression that is not a value, but for which there exists no e’ such that e  e’ is stuck but, all stuck expressions are ill-typed if we type check programs in MinML before running them, they will never get stuck

summary of syntax & dynamic semantics MinML is an idealized language that models some of the basic concepts in functional programming the dynamic semantics satisfies some nice properties: values are irreducible, evaluation is deterministic Next up: typing MinML