A Simple Semantics for Polymorphic Recursion* William L. Harrison, Ph.D Department of Computer Science University of Missouri, Columbia * This research.

Slides:



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

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.
An Abstract Interpretation Framework for Refactoring P. Cousot, NYU, ENS, CNRS, INRIA R. Cousot, ENS, CNRS, INRIA F. Logozzo, M. Barnett, Microsoft Research.
A Fix for Dynamic Scope Ravi Chugh U. of California, San Diego.
Cs776 (Prasad)L4Poly1 Polymorphic Type System. cs776 (Prasad)L4Poly2 Goals Allow expression of “for all types T” fun I x = x I : ’a -> ’a Allow expression.
1 PROPERTIES OF A TYPE ABSTRACT INTERPRETATER. 2 MOTIVATION OF THE EXPERIMENT § a well understood case l type inference in functional programming à la.
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.
8. Introduction to Denotational Semantics. © O. Nierstrasz PS — Denotational Semantics 8.2 Roadmap Overview:  Syntax and Semantics  Semantics of Expressions.
Modular Type Classes Derek Dreyer Robert Harper Manuel M.T. Chakravarty POPL 2007 Nice, France.
DATAFLOW PROCESS NETWORKS Edward A. Lee Thomas M. Parks.
School of Computing and Mathematics, University of Huddersfield CAS810: WEEK 3 LECTURE: LAMBDA CALCULUS PRACTICAL/TUTORIAL: (i) Do exercises given out.
Programming Language Semantics Denotational Semantics Chapter 5 Based on a lecture by Martin Abadi.
1 Operational Semantics Mooly Sagiv Tel Aviv University Textbook: Semantics with Applications.
13. Summary, Trends, Research. © O. Nierstrasz PS — Summary, Trends, Research Summary, Trends, Research...  Summary: functional, logic and object-oriented.
7. Fixed Points. © O. Nierstrasz PS — Fixed Points 7.2 Roadmap  Representing Numbers  Recursion and the Fixed-Point Combinator  The typed lambda calculus.
Control Flow Analysis Mooly Sagiv Tel Aviv University Sunday Scrieber 8 Monday Schrieber.
Proofs are Programs: 19th Century Logic and 21st Century Computing CS 510: Programming Languages (a talk adapted from Philip Wadler)
Programming Language Semantics Mooly SagivEran Yahav Schrirber 317Open space html://
Abstract Interpretation Part I Mooly Sagiv Textbook: Chapter 4.
7. Fixed Points. © O. Nierstrasz PS — Fixed Points 7.2 Roadmap Overview  Representing Numbers  Recursion and the Fixed-Point Combinator  The typed.
Type Inference David Walker COS 441. Criticisms of Typed Languages Types overly constrain functions & data polymorphism makes typed constructs useful.
7. Fixed Points. © O. Nierstrasz PS — Fixed Points 7.2 Roadmap  Representing Numbers  Recursion and the Fixed-Point Combinator  The typed lambda calculus.
12. Summary, Trends, Research. © O. Nierstrasz PS — Summary, Trends, Research Roadmap  Summary: —Trends in programming paradigms  Research:...
Semantics with Applications Mooly Sagiv Schrirber html:// Textbooks:Winskel The.
Functional programming: LISP Originally developed for symbolic computing First interactive, interpreted language Dynamic typing: values have types, variables.
Prof. Aiken CS 294 Lecture 21 Abstract Interpretation Part 2.
Operational Semantics Semantics with Applications Chapter 2 H. Nielson and F. Nielson
Programming Language Semantics Denotational Semantics Chapter 5 Part III Based on a lecture by Martin Abadi.
Cormac Flanagan University of California, Santa Cruz Hybrid Type Checking.
1 Iterative Program Analysis Abstract Interpretation Mooly Sagiv Tel Aviv University Textbook:
NummSquared Coercion make it so! Samuel Howse poohbist.com November 29, 2006 Copyright © 2006 Samuel Howse. All rights reserved.
© Kenneth C. Louden, Chapter 11 - Functional Programming, Part III: Theory Programming Languages: Principles and Practice, 2nd Ed. Kenneth C. Louden.
Fixed Point Illustrations. Simple Examples f : int -> int f(n) = 5 n = 5 is a unique fixed point. f(n) = n^2 – 2 n = 2 and n = -1 are both fixed points.
Freefinement Stephan van Staden, Cristiano Calcagno, Bertrand Meyer Chair of Software Engineering.
© 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.
TIVDM2Functional Programming Language Concepts 1 Concepts from Functional Programming Languages Peter Gorm Larsen.
1 Formal Semantics. 2 Why formalize? ML is tricky, particularly in corner cases generalizable type variables? polymorphic references? exceptions? Some.
Universal Types Report by Matthias Horbach. Contents Types of Polymorphism System F Basic Properties Erasure Impredicativity Parametricity.
1 Alex Proctor and Brian Lee for CSCI 431 at UNCA, Fall 2002 ML (Meta Language) a brief introduction Alex Proctor and Brian Lee For CSCI 431 at the University.
Types and Programming Languages Lecture 12 Simon Gay Department of Computing Science University of Glasgow 2006/07.
Implementing a Dependently Typed λ -Calculus Ali Assaf Abbie Desrosiers Alexandre Tomberg.
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.
A Staged Semantics of Overloading (preliminary) Bill Harrison & Tim Sheard.
Advanced Formal Methods Lecture 4: Isabelle – Types and Terms Mads Dam KTH/CSC Course 2D1453, Some material from Paulson.
1 Reasoning with Infinite stable models Piero A. Bonatti presented by Axel Polleres (IJCAI 2001,
Operational Semantics Mooly Sagiv Tel Aviv University Textbook: Semantics with Applications Chapter.
Types and Programming Languages Lecture 14 Simon Gay Department of Computing Science University of Glasgow 2006/07.
1 Iterative Program Analysis Abstract Interpretation Mooly Sagiv Tel Aviv University Textbook:
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
Operational Semantics Mooly Sagiv Tel Aviv University Sunday Scrieber 8 Monday Schrieber.
Erik Meijer FP101x - Functional Programming Programming in Haskell - Introduction.
서울대한양대 ( 안 산 ) 충남대 1년1년 컴퓨터기초 (C) 컴퓨터프로그래밍 (C, Java) 컴퓨터프로그래밍 (C) 2. 봄 프로그래밍 원리 (Scheme, ML) Structure & Interpretation of Computer Programs 프로그래밍 방법론.
COMP 412, FALL Type Systems C OMP 412 Rice University Houston, Texas Fall 2000 Copyright 2000, Robert Cartwright, all rights reserved. Students.
Arvind Computer Science and Artificial Intelligence Laboratory M.I.T. L05-1 September 21, 2006http:// Types and Simple Type.
Lesson 10 Type Reconstruction
What is a Functional Language?
Textbook: Principles of Program Analysis
CS 611: Lecture 9 More Lambda Calculus: Recursion, Scope, and Substitution September 17, 1999 Cornell University Computer Science Department Andrew Myers.
Graph-Based Operational Semantics
Revisiting Predicate Logic LN chapters 3,4
Finite Automata and Formal Languages
Background In his classic 1972 paper on definitional interpreters, John Reynolds introduced two key techniques: Continuation-passing style - Makes.
L Calculus.
OBJ first-order functional language based on equational logic
Program correctness Axiomatic semantics
Presentation transcript:

A Simple Semantics for Polymorphic Recursion* William L. Harrison, Ph.D Department of Computer Science University of Missouri, Columbia * This research supported in part by subcontract GPACS0016, System Information Assurance II, through OGI/Oregon Health & Sciences University.

What is polymorphic recursion? size runs in O(log n), list length in O(n) Compact list-like structure [Okasaki98] Polymorphic recursion useful in generic programming [Hinze00,HinzeJeuring02]

polymorphic recursion aka “non-uniform recursion” size :: Seq a  Int size :: Seq (a,a)  Int length :: [a]  Int

Roadmap Ohori 89 conservatively extends semantics of STLC to Core-ML Harrison/Kieburtz 05 extend to model & logic of Haskell demand Present work models recursion in Haskell Remaining aspects seem to fit well in this framework In particular, type classes Goal: H98 semantics akin to “Definition of Standard ML” Demand in Haskell 98 [JFP05] Simple Model for Polymorphic Recursion [APLAS05] Goal: Haskell 98 Semantics Simple Model for ML Polymorphism [Ohori89]

Background: Frame Models is a frame model iff

Simple Model for ML polymorphism; Ex: ( x.x) :  a.a  a Denotes at any instance Simple Model conservatively extends model of simply-typed -calculus An alternative [HarperMitchell93] is to model type quantifiers with type abstraction as in System F/polymorphic -calculus [Girard,Reynolds]

Language for Polymorphic Recursion Abstract Syntax for “PR” Language combines features of [Kfoury93] & [Ohori89] special “pfix” binder for polymorphic recursive definitions stratified type language: “simple”, “open”, and “universal”

Type Syntax  is an instantiation if, and only if Stratified Types

Typing Rules for PR  (x) = t  x : t , x :  M:   (fix x. M) :   (x) =     x : ( s  ) , x :  (pfix x. M) :  M: Hindley-Milner PR rules [Kfoury93] *Type system is syntax-oriented [Kfoury93]; I.e., derivations are unique modulo application order of GEN rule.

Typing Rules for PR  (x) =     x : ( s  ) , x :  (pfix x. M) :  M: Leaf in the type derivation of size …

is a pcpo frame if each D  is a pointed cpo w.r.t.,, and For  = [Int]  Int, … Where continuity and fix are defined conventionally: Ex. Pointed CPO Frames

size :: Seq a  Int size :: Seq (a,a)  Int “lives” in D Seq(  ’)  Int “lives” in D Seq(  ’   ’)  Int Where do we solve equations such as ?

Defining pcpo frame P in terms of a given pcpo frame D Frame Objects are type-indexed sets of values Other Structure (lub & p.o. defined pointwise) By Theorem 1 in the paper, P is a pcpo frame

Frame Semantics of PR VAR: PFIX: where Semantics defined by induction on type derivations

Application: Haskell Type Classes The “Eq” class Without Poly-Rec, any Haskell program uses finitely many, statically determinable instances of (==) [Jones94]; not true with Poly-Rec defines (==) at infinitely many types With the Simple Model, “dictionaries” are just denotations

Historical Note Polymorphic Recursion entered Haskell through a “backdoor” when certain expert programmers noticed that the following variety of kludge worked.

Related Work Mycroft 84 introduced PR; gave a model based on ideals [MacQueen, et al. 84] Cousot 97 formulated a hierarchy of type systems (including Mycroft’s) in terms of lattice of abstract interpretations of untyped lambda calculus Henglein 93 showed PR type inference is undecidable Kfoury, et al. 93, gave several type systems for PR; ours is called ML/1 ’ Models of Type classes [WadlerBlott89, Thatte94, StuckeySulzmann04] and Higher-order polymorphism [Jones93]

Conclusions “Textbook” semantics Substance of denotations change (type awareness) Form of semantic definitions mostly familiar Conservative extension of “Simple Model of ML Polymorphism” Straightforward, albeit non- trivial Present work models recursion in Haskell Remaining aspects seem to fit well: type classes & higher- order polymorphism Demand in Haskell 98 [JFP05] Simple Model for Polymorphic Recursion [APLAS05] Goal: Haskell 98 Semantics Simple Model for ML Polymorphism [Ohori89]