Aggregate Data Structures COS 441 Princeton University Fall 2004.

Slides:



Advertisements
Similar presentations
A Third Look At ML 1. Outline More pattern matching Function values and anonymous functions Higher-order functions and currying Predefined higher-order.
Advertisements

Type Inference David Walker COS 320. Criticisms of Typed Languages Types overly constrain functions & data polymorphism makes typed constructs useful.
Type Checking, Inference, & Elaboration CS153: Compilers Greg Morrisett.
Semantics Static semantics Dynamic semantics attribute grammars
Attribute Grammars Prabhaker Mateti ACK: Assembled from many sources.
- Vasvi Kakkad.  Formal -  Tool for mathematical analysis of language  Method for precisely designing language  Well formed model for describing and.
ICE1341 Programming Languages Spring 2005 Lecture #6 Lecture #6 In-Young Ko iko.AT. icu.ac.kr iko.AT. icu.ac.kr Information and Communications University.
1 How to transform an analyzer into a verifier. 2 OUTLINE OF THE LECTURE a verification technique which combines abstract interpretation and Park’s fixpoint.
CS7100 (Prasad)L16-7AG1 Attribute Grammars Attribute Grammar is a Framework for specifying semantics and enables Modular specification.
Lecture # 21 Chapter 6 Uptill 6.4. Type System A type system is a collection of rules for assigning type expressions to the various parts of the program.
Getting started with ML ML is a functional programming language. ML is statically typed: The types of literals, values, expressions and functions in a.
Type checking © Marcelo d’Amorim 2010.
ML: a quasi-functional language with strong typing Conventional syntax: - val x = 5; (*user input *) val x = 5: int (*system response*) - fun len lis =
Dynamic Typing COS 441 Princeton University Fall 2004.
Elaboration or: Semantic Analysis Compiler Baojian Hua
Introduction to ML – Part 1 Frances Spalding. Assignment 1 chive/fall05/cos441/assignments/a1.ht m
Type Checking.
Quick Review Get paper and pencil out. Not graded just for review.
Subtyping COS 441 Princeton University Fall 2004.
Denotational Semantics Syntax-directed approach, generalization of attribute grammars: –Define context-free abstract syntax –Specify syntactic categories.
Data Abstraction COS 441 Princeton University Fall 2004.
Parametric Polymorphism COS 441 Princeton University Fall 2004.
ML: a quasi-functional language with strong typing Conventional syntax: - val x = 5; (*user input *) val x = 5: int (*system response*) - fun len lis =
Inductive Definitions COS 510 David Walker. Inductive Definitions Inductive definitions play a central role in the study of programming languages They.
Misc. Announcements Assignment available end of the day today –Due back in 11/03 (after break) Will also update slides on website –Today Midterm next week.
Introduction to ML - Part 2 Kenny Zhu. What is next? ML has a rich set of structured values Tuples: (17, true, “stuff”) Records: {name = “george”, age.
Introduction to ML Last time: Basics: integers, Booleans, tuples,... simple functions introduction to data types This time, we continue writing an evaluator.
Syntax With Binders COS 441 Princeton University Fall 2004.
MinML: an idealized programming language CS 510 David Walker.
Dynamic Semantics COS 441 Princeton University Fall 2004.
HOT Programming in Java COS 441 Princeton University Fall 2004.
1 Semantics Q S EMANTICS (Q1,’07) Week 4 Jacob Andersen PhD student
Feather-Weight Java COS 441 Princeton University Fall 2004.
1 Type Type system for a programming language = –set of types AND – rules that specify how a typed program is allowed to behave Why? –to generate better.
Semantics for MinML COS 441 Princeton University Fall 2004.
CS784 (Prasad)L167AG1 Attribute Grammars Attribute Grammar is a Framework for specifying semantics and enables Modular specification.
Chapter Twenty-ThreeModern Programming Languages1 Formal Semantics.
ISBN Chapter 3 Describing Semantics -Attribute Grammars -Dynamic Semantics.
CS 363 Comparative Programming Languages Semantics.
Formal Semantics Chapter Twenty-ThreeModern Programming Languages, 2nd ed.1.
Lee CSCE 314 TAMU 1 CSCE 314 Programming Languages Haskell: Types and Classes Dr. Hyunyoung Lee.
Cs7120 (prasad)L7-TDEF1 Type Definitions. cs7120 (prasad)L7-TDEF2 Concrete Types Primitive types ( int, bool, char, string, etc ) Type constructors (
Propositional Calculus CS 270: Mathematical Foundations of Computer Science Jeremy Johnson.
A Third Look At ML Chapter NineModern Programming Languages, 2nd ed.1.
Chapter 3 Part II Describing Syntax and Semantics.
Semantics In Text: Chapter 3.
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.
1 Compiler Construction (CS-636) Muhammad Bilal Bashir UIIT, Rawalpindi.
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
1 Static Contract Checking for Haskell Dana N. Xu University of Cambridge Joint work with Simon Peyton Jones Microsoft Research Cambridge Koen Claessen.
CSED101 INTRODUCTION TO COMPUTING SUM TYPE 유환조 Hwanjo Yu.
COMP 412, FALL Type Systems II C OMP 412 Rice University Houston, Texas Fall 2000 Copyright 2000, Robert Cartwright, all rights reserved. Students.
CMSC 330: Organization of Programming Languages Operational Semantics.
More Data Types CSCE 314 Spring CSCE 314 – Programming Studio Defining New Data Types Three ways to define types: 1.type – Define a synonym for.
1 Announcements Exam 2 graded Rainbow grades: HW1-5, Exam 1-2, Quiz 1-6 Part 1: Problem 1, Problem 2, will go over 2 Part 2: Problem 1, Problem 2 Part.
Programming Languages and Compilers (CS 421)
Principles of programming languages 12: Functional programming
ML: a quasi-functional language with strong typing
Programming Languages Dan Grossman 2013
Type Definitions cs776 (prasad) L8tdef.
Lesson 4 Typed Arithmetic Typed Lambda Calculus
Abstract Syntax Prabhaker Mateti 1.
Types and Classes in Haskell
Compiler Construction
6.001 SICP Interpretation Parts of an interpreter
Programming Languages Dan Grossman 2013
Compiler Construction
Presentation transcript:

Aggregate Data Structures COS 441 Princeton University Fall 2004

Data-Structures for MinML Products Types –n-tuples general case, will study 0-tuple (unit) and 2-tuples (pairs) Sums Types –Tagged types (We can just study binary tags) Recursive Types –Lists, Trees, … etc.

Product Types

Products: Static Semantics

Products: Dynamic Semantics

Sum Types

Sums: Static Semantics

Sums: Dynamic Semantics

Recursive Types

Rec. Types: Static Semantics

datatype nat = Zero | Succ of nat e : rec t is (Zero + Succ of t) unroll(e) : {(rec t is (Zero + Succ of t))/t} (Zero + Succ of t) unroll(e) : (Zero + Succ of (rec t is (Zero + Succ of t))

Rec. Types: Dynamic Semantics

Derived Types bool  unit + unit ilist  rec t is (unit + (int * t))

Examples: Booleans true  inl unit + unit (()) false  inr unit + unit (()) if(e,e 1,e 2 )  case  e 0 of inl(x:unit) => e 1 | inr(y:unit) => e 2

Examples: Lists ilist  rec t is (unit + (int * t)) nil  roll(inl unit +(int * ilist) (())) cons(e 1,e 2 )  roll(inr unit +(int * ilist) ((e 1,e 2 )))

Examples: Lists listcase e of nil => e 1 | cons(x,y) => e 2  case unroll(e 0 ) of inl(_:unit) => e 1 | inr(z:int * ilist) => split z as (x,y) in e 2

Roll/Unroll The roll and unroll primitives are there just to make the proof a bit easier and to guarantee syntax directed checking The are not needed in a realistic implementation only act as a notational fiction Compare to to inl/inr which have a real computational purpose

Some Subtle Bugs Harper’s notes present rules/syntax that are “buggy” Rules presented in a fashion that makes implementing type checking in a bottom up way impossible Also contains some redundant info Abstract syntax corrected in homework

Checking vs Inference We can view the relation  ` e :  in several ways A predicate on environments expressions and types val check : (env * exp * typ) -> boo l A function partial function that computes the type of an expression val infer : (env * exp) -> typ

Type Annotations Abstract syntax is “decorated” with type information to make checking/inference syntax directed More sophisticated implementations of checkers can avoid the need for type information

Case Can infer  by computing type of e 1 and e 2 Worth keeping for better error reporting. redundant

Recursive Types If we compute the type for e still must “guess”  to check rule Homework annotates roll to avoid need to “guess”

Example roll(inl unit + (rec t is (unit + t)) (unit)) : rec t is  What should  be for the above to type check?

Example roll(inl unit + (rec t is (unit + t)) (unit)) : rec t is  What should  be for the above to type check?  = (unit + t) {rec t is (unit + t) / t} (unit + t) = unit + rec t is (unit + t)

Summary Can express many interesting type using these primitive type constructors Algorithmic issues of type-checking sometime clutter the presentation of the rules