Arvind Computer Science and Artificial Intelligence Laboratory M.I.T. L04Ext-1 September 21, 2006http://www.csg.csail.mit.edu/6.827 Some more thoughts.

Slides:



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

Substitution & Evaluation Order cos 441 David Walker.
Elements of Lambda Calculus Functional Programming Academic Year Alessandro Cimatti
1 Programming Languages (CS 550) Lecture Summary Functional Programming and Operational Semantics for Scheme Jeremy R. Johnson.
Evaluators for Functional Programming Chapter 4 1 Chapter 4 - Evaluators for Functional Programming.
INF 212 ANALYSIS OF PROG. LANGS LAMBDA CALCULUS Instructors: Crista Lopes Copyright © Instructors.
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.
Syntax With Binders COS 441 Princeton University Fall 2004.
מבוא מורחב - שיעור 2 1 Lecture 2 - Substitution Model (continued) - Recursion - Block structure and scope (if time permits)
Comp 205: Comparative Programming Languages Semantics of Functional Languages Term- and Graph-Rewriting The λ-calculus Lecture notes, exercises, etc.,
PPL Syntax & Formal Semantics Lecture Notes: Chapter 2.
PPL Syntax & Formal Semantics Lecture Notes: Chapter 2.
1 Saves repeated renaming and substitution: explicit substitution is replaced by variable bindings using new data structures (frame, environment). Can.
Functional Programming Element of Functional Programming.
Chapter 2 Syntax A language that is simple to parse for the compiler is also simple to parse for the human programmer. N. Wirth.
March 4, 2008 DF4-1http://csg.csail.mit.edu/arvind/ From Id/pH to Dataflow Graphs Arvind Computer Science & Artificial Intelligence Lab Massachusetts Institute.
The Relational Model: Relational Calculus
Functional Programming Universitatea Politehnica Bucuresti Adina Magda Florea
10/12/20151 GC16/3C11 Functional Programming Lecture 3 The Lambda Calculus A (slightly) deeper look.
CSE S. Tanimoto Lambda Calculus 1 Lambda Calculus What is the simplest functional language that is still Turing complete? Where do functional languages.
© Kenneth C. Louden, Chapter 11 - Functional Programming, Part III: Theory Programming Languages: Principles and Practice, 2nd Ed. Kenneth C. Louden.
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 The Evaluator. 2 Compiler vs. Interpreter Command Processing Unit The Computer Program in Low Level Machine Language Program in High Level Language.
© Kenneth C. Louden, Chapter 11 - Functional Programming, Part III: Theory Programming Languages: Principles and Practice, 2nd Ed. Kenneth C. Louden.
Arvind Computer Science and Artificial Intelligence Laboratory M.I.T. L06-1 September 26, 2006http:// Type Inference September.
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.
Types and Programming Languages Lecture 6 Simon Gay Department of Computing Science University of Glasgow 2006/07.
1 Formal Semantics. 2 Why formalize? ML is tricky, particularly in corner cases generalizable type variables? polymorphic references? exceptions? Some.
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.
Basic Scheme February 8, 2007 Compound expressions Rules of evaluation Creating procedures by capturing common patterns.
1/33 Basic Scheme February 8, 2007 Compound expressions Rules of evaluation Creating procedures by capturing common patterns.
COMP 412, FALL Type Systems II C OMP 412 Rice University Houston, Texas Fall 2000 Copyright 2000, Robert Cartwright, all rights reserved. Students.
CSE-321 Programming Languages -Calculus (II) POSTECH March 26, 2007 박성우.
Types and Programming Languages Lecture 16 Simon Gay Department of Computing Science University of Glasgow 2006/07.
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.
Arvind Computer Science and Artificial Intelligence Laboratory M.I.T. L05-1 September 21, 2006http:// Types and Simple Type.
CS321 Functional Programming 2 © JAS Implementation using Combinators This approach builds upon the λ-calculus model. The aim is to translate.
A LISP interepreter for the Lambda Calculus Functional Programming
1 Sections 3.1 – 3.2a Basic Syntax and Semantics Fundamentals of Java: AP Computer Science Essentials, 4th Edition Lambert / Osborne.
Operational Semantics of Scheme
CS 550 Programming Languages Jeremy Johnson
Unit – 3 :LAMBDA CALCULUS AND FUNCTIONAL PROGRAMMING
Lecture 6: Lambda Calculus
Basic Scheme February 8, 2007 Compound expressions Rules of evaluation
Introduction to Logic for Artificial Intelligence Lecture 2
The interpreter.
CS 611: Lecture 9 More Lambda Calculus: Recursion, Scope, and Substitution September 17, 1999 Cornell University Computer Science Department Andrew Myers.
September 4, 1997 Programming Languages (CS 550) Lecture 6 Summary Operational Semantics of Scheme using Substitution Jeremy R. Johnson TexPoint fonts.
Lambda Calculus Revisited
Env. Model Implementation
Carlos Varela Rennselaer Polytechnic Institute September 4, 2015
Programming Languages and Compilers (CS 421)
A-calculus with Constants and Let-blocks
Announcements Quiz 6 HW7 due Tuesday, October 30
CS 611: Lecture 10 More Lambda Calculus September 20, 1999
Math I Quarter I Standards
Material in the textbook Sections to 1.2.1
Lecture 14: The environment model (cont
Announcements Exam 2 on Friday, November 2nd Topics
L Calculus.
Programming Languages and Compilers (CS 421)
Programming Languages and Compilers (CS 421)
Bluespec-7: Semantics of Bluespec
Lecture 13: Assignment and the Environment Model (EM)
CSE S. Tanimoto Lambda Calculus
CS 611: Lecture 10 More Lambda Calculus September 20, 1999
Recursive Procedures and Scopes
Presentation transcript:

Arvind Computer Science and Artificial Intelligence Laboratory M.I.T. L04Ext-1 September 21, 2006http:// Some more thoughts on let September 21, 2006

L04Ext-2 September 21, 2006http:// Why let Calculus ? Programming without (recursive) let blocks is tedious Recursive let blocks can be translated into the -calculus with constants and Y combinator but the translation is is complicated (not simple syntactical substitutions) ; is not intuitive or illustrative does not match any implementation  extend the -calculus with recursive let blocks.

L04Ext-3 September 21, 2006http:// -calculus with Constants & Letrec E ::= x | x.E | E E | Cond (E, E, E) | PF k (E 1,...,E k ) | CN 0 | CN k (E 1,...,E k ) | CN k (SE 1,...,SE k ) | let S in E PF 1 ::= negate | not |... | Prj 1 | Prj 2 |... PF 2 ::= + |... CN 0 ::= Number | Boolean CN 2 ::= cons |... Statements S ::=  | x = E | S; S Variables on the LHS in a let expression must be pairwise distinct not in initial terms

L04Ext-4 September 21, 2006http:// Issues in giving semantics for lets- 1 1.Creating redexes ((let S in x.e 1 ) e 2 ) How do we juxtapose (x.e 1 ) e 2 ? Solution: Lifting rules

L04Ext-5 September 21, 2006http:// Issues in giving semantics for lets How to refer to a variable binding let f = x.e 1 y = e 2 e 3 in (f y) + y How and when f and y refer to their definitions ((x.e 1 ) y) + y ? Solution: Instantiation rules

L04Ext-6 September 21, 2006http:// How to define the operational semantics of let blocks: Environments An environment-based interpreter. –An environment where all the (variable name, value) bindings are kept and is passed around for expression evaluation –When a let expression is encountered the environment is extended with all the let-bindings. Very complicated if the environment contains unevaluated expressions –Not abstract enough – too many concrete data structures and associated functions for proper execution Eval [[e]]  environment

L04Ext-7 September 21, 2006http:// How to define the operational semantics of let blocks: graphs –Quite complicated to explain -substitution in a graph based interpreter let f = x.e 1 y = e 2 e 3 in (f y) + y x e1e1 f e2e2 e3e3 ap y A let simply represents a wiring diagram, i.e., a graph + ap root

L04Ext-8 September 21, 2006http:// How to define the operational semantics of let blocks: via a calculus Rewrite rules –Lifting rules –Instantiation rules (need some new way of writing rules): contexts,... Reduction Strategy Normal forms? Equivalences? let x = 5 in x let x = 5 in 5 5let x = 5 y = 6 in x the let calculus

L04Ext-9 September 21, 2006http:// Lifting Rules (let S’ in e’) is the   -renamed (let S in e) to avoid name conflicts in the following rules: x = let S in e  let S 1 in (let S in e)  (let S in e) e 1  Cond((let S in e), e 1, e 2 )  PF k (e 1,...(let S in e),...e k )  x = e’; S’ let S 1 ; S’ in e’ let S’ in e’ e 1 let S’ in Cond(e’, e 1, e 2 ) let S’ in PF k (e 1,...e’,...e k )

L04Ext-10 September 21, 2006http:// let Instantiation Rules A free variable in an expression can be instantiated by a simple expression Instantiation rule 2 (x = a ; SC[x])  simple expression free occurrence of x in some context C renamed C[ ] to avoid free- variable capture Instantiation rule 1 (let x = a ; S in C[x])  (let x = a ; S in C’[a]) Instantiation rule 3 x = a  where a = C[x] (x = a ; SC’[a]) x = C’[C[x]]

L04Ext-11 September 21, 2006http:// Once we have lets we use them elsewhere too... The normal -rule (x.e) e a  e [e a /x] is replaced the following -rule (x.e) e a  let t = e a in e[t/x] where t is a new variable and the Instantiation rules which are used to refer to the value of a variable