Types and Programming Languages Lecture 12a Simon Gay Department of Computing Science University of Glasgow 2006/07.

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 8 Simon Gay Department of Computing Science University of Glasgow 2006/07.
Types and Programming Languages Lecture 13 Simon Gay Department of Computing Science University of Glasgow 2006/07.
Types and Programming Languages Lecture 15 Simon Gay Department of Computing Science University of Glasgow 2006/07.
Types and Programming Languages Lecture 7 Simon Gay Department of Computing Science University of Glasgow 2006/07.
Boyce/DiPrima 9th ed, Ch 2.4: Differences Between Linear and Nonlinear Equations Elementary Differential Equations and Boundary Value Problems, 9th edition,
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.
With Microsoft Access 2010© 2011 Pearson Education, Inc. Publishing as Prentice Hall1 PowerPoint Presentation to Accompany GO! with Microsoft ® Access.
Read Chapter 17 of the textbook
ECE 331 – Digital System Design
December 8, 2009Theory of Computation Lecture 22: Turing Machines IV 1 Turing Machines Theorem 1.1: Any partial function that can be computed by a Post-
Chapter 6. 2 Objectives You should be able to describe: Function and Parameter Declarations Returning a Single Value Pass by Reference Variable Scope.
Comp 205: Comparative Programming Languages Functional Programming Languages: More Haskell Lecture notes, exercises, etc., can be found at:
Getting Started Chapter One DAVID M. KROENKE and DAVID J. AUER DATABASE CONCEPTS, 5 th Edition.
Algorithm Programming Coding Advices Bar-Ilan University תשס " ו by Moshe Fresko.
Simplifying Variable Expressions (Negative Units - Day 2) We are learning to…simplify variable expressions by combining like terms. Saturday, August 08,
Exponents and Polynomials
1 Topic Mathematical Proofs. 2 Topic Mathematical Proofs California Standards: 24.2 Students identify the hypothesis and conclusion in logical.
Vocabulary Chapter 4. In a relationship between variables, the variable that changes with respect to another variable is called the.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved Chapter 12 Object-Oriented.
CIS 103 — Applied Computer Technology Last Edited: September 17, 2010 by C.Herbert Using Database Management Systems.
CS1Q Computer Systems Lecture 8
Computing Science 1P Lecture 13: Friday 26 th January Simon Gay Department of Computing Science University of Glasgow 2006/07.
Polymorphism, Inheritance Pt. 1 COMP 401, Fall 2014 Lecture 7 9/9/2014.
1 Science as a Process Chapter 1 Section 2. 2 Objectives  Explain how science is different from other forms of human endeavor.  Identify the steps that.
Factor Analysis Anthony Sealey University of Toronto This material is distributed under an Attribution-NonCommercial-ShareAlike 3.0 Unported Creative Commons.
Copyright © 2010 Pearson Education, Inc. Lecture Outline Chapter 11 Physics, 4 th Edition James S. Walker.
© 2007 Pearson Prentice Hall This work is protected by United States copyright laws and is provided solely for the use of instructors in teaching their.
Variances Add Chapter 16 – Day 2 In chapter 4, we learned that what effect transformations had on shape, center and spread. –When adding (or subtracting)
1 Compiler Construction (CS-636) Muhammad Bilal Bashir UIIT, Rawalpindi.
Computing Science 1P Lecture 17: Friday 23 rd February Simon Gay Department of Computing Science University of Glasgow 2006/07.
Chapter 9: Functional Programming in a Typed Language.
2.1 Day 2 Linear Transformations and their Inverses For an animation of this topic visit:
Aron, Aron, & Coups, Statistics for the Behavioral and Social Sciences: A Brief Course (3e), © 2005 Prentice Hall Chapter 12 Making Sense of Advanced Statistical.
Elementary statistics for foresters Lecture 5 Socrates/Erasmus WAU Spring semester 2005/2006.
Hirophysics.com Steven Jeffrey K irkup. Hirophysics.com What is Object Oriented Programming (OOP)? Essentially, OOP is a protocol that can be followed.
Types and Programming Languages Lecture 6 Simon Gay Department of Computing Science University of Glasgow 2006/07.
Comp 248 Introduction to Programming Chapter 4 & 5 Defining Classes Part B Dr. Aiman Hanna Department of Computer Science & Software Engineering Concordia.
Section Copyright © 2014, 2012, 2010 Pearson Education, Inc. Lecture Slides Elementary Statistics Twelfth Edition and the Triola Statistics Series.
Types and Programming Languages Lecture 12 Simon Gay Department of Computing Science University of Glasgow 2006/07.
Fall 2008Programming Development Techniques 1 Topic 5 Data Abstraction Note: This represents a change in order. We are skipping to chapter 2 without finishing.
Advanced Formal Methods Lecture 3: Simply Typed Lambda calculus Mads Dam KTH/CSC Course 2D1453, Some material from B. Pierce: TAPL + some from.
Types and Programming Languages Lecture 11 Simon Gay Department of Computing Science University of Glasgow 2006/07.
CS1Q Computer Systems Lecture 8
1 Chapter 1 Introduction to Differential Equations 1.1 Introduction The mathematical formulation problems in engineering and science usually leads to equations.
Types and Programming Languages Lecture 14 Simon Gay Department of Computing Science University of Glasgow 2006/07.
Types and Programming Languages Lecture 10 Simon Gay Department of Computing Science University of Glasgow 2006/07.
Types and Programming Languages Lecture 3 Simon Gay Department of Computing Science University of Glasgow 2006/07.
Introduction to Physical Science Chapter 1 The Nature of Science.
Types and Programming Languages Lecture 16 Simon Gay Department of Computing Science University of Glasgow 2006/07.
Differential Equations Solving First-Order Linear DEs Prepared by Vince Zaccone For Campus Learning Assistance Services at UCSB.
Advanced Engineering Mathematics 6th Edition, Concise Edition
Objects as a programming concept
CS1371 Introduction to Computing for Engineers
Adding and Subtracting Polynomials
Making Sense of Advanced Statistical Procedures in Research Articles
CHAPTER 10 Correlation and Regression (Objectives)
Chapter 1 Studying Science
The Independent Study Process
Lecture Slides Elementary Statistics Twelfth Edition
إعداد وتقديم الخبيرة التربوية
Topic 3: Data Hexadecimal.
Lecture Outline Chapter 11 Physics, 4th Edition James S. Walker
Lecture Outline Chapter 11 Physics, 4th Edition James S. Walker
TE2: Combining Like Terms
Lecture Slides Elementary Statistics Twelfth Edition
Getting Started Chapter One DATABASE CONCEPTS, 5th Edition
Review Functions Lists Today: Let expressions
Presentation transcript:

Types and Programming Languages Lecture 12a Simon Gay Department of Computing Science University of Glasgow 2006/07

2005/06Types and Programming Languages Lecture 16 - Simon Gay2 Data Structures with Linear Types It makes sense to consider data structures in a linear type system. Of course we must be careful with the typing rules. Pairs The natural concept is a pair of values, both of which will be used exactly once. The type of linear pairs is traditionally written T  U (pronounced “tensor”). If we have e : T  U then both components must be used. This makes it tricky to work with fst and snd because they discard the other component.

2005/06Types and Programming Languages Lecture 16 - Simon Gay3 Linear Pairs:  The easiest way to formulate extraction of components of  is to use a split construct: split e as (x,y) in e’ When you have worked out the typing rules for split in the non-linear case (for the assessed exercise), you will be able to see how it works in the linear case. The typing rule for construction of linear pairs is: Linear record types can be considered similarly, using a split instead of field projection.

2005/06Types and Programming Languages Lecture 16 - Simon Gay4 Linear Pairs and Currying Now we have a dual view of linear functions of two parameters, analogous to the familiar curried/uncurried view in functional programming. A  B –o C is the type of a function which is given a pair of values and uses them both to produce a result. A –o B –o C is the type of a curried function which is given two values separately and uses them both to produce a result.

2005/06Types and Programming Languages Lecture 16 - Simon Gay5 Linear Pairs: & There is a second kind of linear pair. T & U (pronounced “with”) is a type of pairs such that one or other of the components must be used, but not both. For this kind of pair, projections make sense: fst : A & B –o A snd : A & B –o B The typing rule for pair formation is: Note the same environment  everywhere.

2005/06Types and Programming Languages Lecture 16 - Simon Gay6 Linear Pairs: & The type constructor & is what’s needed to convert the conditional into a function (we would also want call-by-name): cond : bool  (T & T) –o T Exercise: extend the proof of linear type safety to both kinds of linear pair.

2005/06Types and Programming Languages Lecture 16 - Simon Gay7 Combining Linear and Non-Linear Data In a practical programming language we would usually want to combine linear and standard (non-linear) constructs. A general way of doing this is described by David Walker in Chapter 1 of “Advanced Topics in Types and Programming Languages” (edited by Benjamin Pierce). Every type constructor can be defined in linear and unlimited versions. ( T & U doesn’t fit into this pattern.)

2005/06Types and Programming Languages Lecture 16 - Simon Gay8 Combining Linear and Non-Linear Data The typing rules can be generalized so that they handle both linear and non-linear parts of the environment. A nice way of doing this is to define a partial operation + on environments:  + x:T = , x:Tif x    + x:T =  if T is unlimited and x:T    + x:Tis undefined otherwise  +  is defined by adding the entries in  one at a time to .

2005/06Types and Programming Languages Lecture 16 - Simon Gay9 Combining Linear and Non-Linear Data Typing rules are defined in the following way: with the implicit hypothesis that  +  must be defined. This covers both the non-linear (must be the same) and linear (put them together) entries in the environment. Furthermore, we must not construct an unlimited data structure containing linear data.

2005/06Types and Programming Languages Lecture 16 - Simon Gay10 Combining Linear and Non-Linear Data For example, the rule for constructing an unlimited function is The rules for constants and variables allow unlimited entries in the environment to be discarded: For full details, read Walker’s chapter.