Dependent Polymorphism. Makoto Hamana

Size: px
Start display at page:

Download "Dependent Polymorphism. Makoto Hamana"

Transcription

1 1 Dependent Polymorphism Makoto Hamana Department of Computer Science, Gunma University, Japan hamana/

2 This Talk 2 [I] A semantics for dependently-typed programming [II] A kind of polymorphism from semantics dependent polymorphism

3 This Talk 3 [I] A semantics for dependently-typed programming [II] A kind of polymorphism from semantics dependent polymorphism

4 4 Dependent type

5 Dependently-typed Programming, Now! 5 (i) Agda [Chalmers 07-,AIST] (ii) Coq with program/equations tactic [Sozeau ICFP 07,ITP 10] (iii) Epigram [McBride,McKinna 04-] (iv) Haskell with type classes/gadts [McBride JFP 02, Hinze 03] Origin Dependently Typed Functional Programs and Their Proofs Conor McBride, Ph.D thesis, University of Edinburgh, 1999.

6 How to Use Dependent Types in Programming? 6 data Nat : Set where zero : Nat suc : Nat -> Nat data Vec : Nat -> Set where -- an inductive family [] : Vec zero _::_ : {n : Nat} -> (a : A) -> Vec n -> Vec (suc n) Vec type of length-indexed lists [] : Vec zero a1 :: [] : Vec (suc zero) a2 :: a1 :: [] : Vec (suc (suc zero))

7 How to Use Dependent Types in Programming? 7 Safe head head : {n : Nat} -> Vec (suc n) -> A head (x :: xs) = x Never fails

8 Typical Example: append 8 _++_ : {m n : Nat} -> Vec m -> Vec n -> Vec (m + n) [] ++ ys = ys (x :: xs) ++ ys = x :: (xs ++ ys) The index of result type precisely specifies the resulting list Is it always possible?

9 More Example: filter 9 Agda filter : {n : Nat} -> (Nat -> Bool) -> Vec n -> Vec (?) filter p [] = [] filter p (x :: xs) with p x... False = filter p xs... True = x :: filter p xs

10 More Example: filter 10 Agda: first attempt filter : {n : Nat} -> (p : Nat -> Bool) -> (xs : Vec n) -> Vec (length (filter p xs)) filter p [] = [] filter p (x :: xs) with p x... False = filter p xs... True = x :: filter p xs

11 More Example: filter 11 Agda: correct code len-filter : {n : Nat} -> (Nat -> Bool) -> Vec n -> Nat len-filter p [] = 0 len-filter p (x :: xs) with p x... False = len-filter p xs... True = suc (len-filter p xs) filter : {n : Nat} -> (p : Nat -> Bool) -> (xs : Vec n) -> Vec (len-filter p xs) filter p [] = [] filter p (x :: xs) with p x... False = filter p xs... True = x :: filter p xs

12 More Example: filter 12 Agda: correct code len-filter : {n : Nat} -> (Nat -> Bool) -> Vec n -> Nat len-filter p [] = 0 len-filter p (x :: xs) with p x... False = len-filter p xs... True = suc (len-filter p xs) filter : {n : Nat} -> (p : Nat -> Bool) -> (xs : Vec n) -> Vec (len-filter p xs) filter p [] = [] Dependent polymorphism helps filter p (x :: xs) with p x... False = filter p xs... True = x :: filter p xs

13 Classification of Polymorphism 13 Straychey [1967], Reynolds [1983] Ad-hoc Int Int + Int Int Real Real + Real Real Parametric Int Int Int R R R Real Real Real fst Int Int R fst Real Real Dependent V ec V ec V ec + V ec dependency Nat Nat Nat Nat +

14 This Talk 14 [I] A semantics for dependently-typed programming [II] A kind of polymorphism from semantics

15 New Semantics of Inductive Families 15 1) Simplified version of semantics of dependently-sorted abstract syntax [Fiore LICS 08] 2) Dependency category S of sorts 3) The category of discourse is Set S

16 Dependency Category S 16 data N at : Set where zero : Nat suc : Nat Nat data Vec : Nat Set where nil : Vec Zero cons : (n : Nat) (a : A) Vec n Vec (suc n) Dependency category S of sorts skeletal, DAG N len V Objects: sorts Arrows : sort dependencies

17 Semantic Construction of Models 17 data Nat : Set where zero : Nat suc : Nat Nat data Vec : Nat Set where nil : Vec Zero cons : (n : Nat) (a : A) Vec n Vec (suc n) Functor F : Set S Set S modelling an inductive family Initial F -algebra

18 Why Interesting? Programming Viewpoint 18 The category of discourse Set S A natural transformation f : A B in Set S is a family of functions {f s : A s B s s S} satisfying naturality polymorphism? s A s f s B s d s A(d) As f s B s B(d) in S in Set

19 Sort Dependency in Models 19 Term model T Set S T N = {zero} {suc(n) n T N } T V = {nil} {cons(n, b, y) n T N, b T B, y T V, T (len)(y) = n} Functoriality of T : S Set N len V in S T T N T (len) T V in Set

20 Sort Dependency in Model 20 Term model T Set S T N = {zero} {suc(n) n T N } T V = {nil} {cons(n, b, y) n T N, b T B, y T V, T (len)(y) = n} Functoriality of T : S Set N len V in S T T N T (len) length T V in Set 0 nil suc(n) cons(n, a, y) term level dependency

21 Dependent Polymorphism : V ec(m) V ec(n) V ec(m + n) + : Nat Nat nil ++ ys = ys zero + y = y (x : xs) ++ ys = x : (xs ++ ys) suc(n) + y = suc(n + y) V T V T V + T V

22 Dependent Polymorphism : V ec(m) V ec(n) V ec(m + n) + : Nat Nat nil ++ ys = ys zero + y = y (x : xs) ++ ys = x : (xs ++ ys) suc(n) + y = suc(n + y) V T V T V + T V len N T len T len T N T N + T T N len in S in Set

23 Dependent Polymorphism : V ec(m) V ec(n) V ec(m + n) + : Nat Nat nil ++ ys = ys zero + y = y (x :: xs) ++ ys = x :: (xs ++ ys) suc(n) + y = suc(n + y) V T V T V + T V len N T len T len T N T N + T T N len in S in Set T T Schematic definition z y = y c(n) y = c(n y) T in Set S is dependently polymorphic

24 Conclusion: What types admit this reading? When indices are the shapes of data in a type (i) Vectors a2 :: (a1 :: []) : Vec (suc (suc zero)) (ii) Shape indexed type of trees [Hamana LMCS 10] e.g. bin( lf(3), lf(5) ) : Tree (B(L,L)) 2. When indices are calculated by fold Theoretical basis of code reuse in dependently-typed programming

Initial Algebra Semantics for Cyclic Sharing Structures. Makoto Hamana

Initial Algebra Semantics for Cyclic Sharing Structures. Makoto Hamana Initial Algebra Semantics for Cyclic Sharing Structures Makoto Hamana Department of Computer Science, Gunma University, Japan July, 2009, TLCA 09 http://www.cs.gunma-u.ac.jp/ hamana/ This Work How to inductively

More information

Representing Cyclic Structures as Nested Datatypes. Makoto Hamana

Representing Cyclic Structures as Nested Datatypes. Makoto Hamana Representing Cyclic Structures as Nested Datatypes Makoto Hamana Department of Computer Science, Gunma University, Japan Joint work with Neil Ghani Tarmo Uustalu Varmo Vene U. Nottingham U. Tallinn U.

More information

Logic - CM0845 Introduction to Haskell

Logic - CM0845 Introduction to Haskell Logic - CM0845 Introduction to Haskell Diego Alejandro Montoya-Zapata EAFIT University Semester 2016-1 Diego Alejandro Montoya-Zapata (EAFIT University) Logic - CM0845 Introduction to Haskell Semester

More information

Coq with Classes. Matthieu Sozeau. Journées PPS 2011 September 5th 2011 Trouville, France. Project Team πr 2 INRIA Paris

Coq with Classes. Matthieu Sozeau. Journées PPS 2011 September 5th 2011 Trouville, France. Project Team πr 2 INRIA Paris Coq with Classes Matthieu Sozeau Project Team πr 2 INRIA Paris Journées PPS 2011 September 5th 2011 Trouville, France This talk A quick overview of Coq Elaboration Type Classes Matthieu Sozeau - Coq with

More information

Alonzo a Compiler for Agda

Alonzo a Compiler for Agda Alonzo a Compiler for Agda Marcin Benke Institute of Informatics, Warsaw University, ben@mimuw.edu.pl 1 Introduction Agda [Norell, 2007] is an interactive system for developing constructive proofs in a

More information

Advanced Type System Features Tom Schrijvers. Leuven Haskell User Group

Advanced Type System Features Tom Schrijvers. Leuven Haskell User Group Advanced Type System Features Tom Schrijvers Leuven Haskell User Group Data Recursion Genericity Schemes Expression Problem Monads GADTs DSLs Type Type Families Classes Lists and Effect Free Other Handlers

More information

Programming with Universes, Generically

Programming with Universes, Generically Programming with Universes, Generically Andres Löh Well-Typed LLP 24 January 2012 An introduction to Agda Agda Functional programming language Static types Dependent types Pure (explicit effects) Total

More information

Provably Correct Software

Provably Correct Software Provably Correct Software Max Schäfer Institute of Information Science/Academia Sinica September 17, 2007 1 / 48 The Need for Provably Correct Software BUT bugs are annoying, embarrassing, and cost gazillions

More information

Generic programming with ornaments and dependent types

Generic programming with ornaments and dependent types Utrecht University Master Thesis Computing Science Generic programming with ornaments and dependent types Yorick Sijsling Supervisors dr. Wouter Swierstra prof. dr. Johan Jeuring June 29, 2016 Abstract

More information

Structural polymorphism in Generic Haskell

Structural polymorphism in Generic Haskell Structural polymorphism in Generic Haskell Andres Löh andres@cs.uu.nl 5 February 2005 Overview About Haskell Genericity and other types of polymorphism Examples of generic functions Generic Haskell Overview

More information

Lecture 8: Summary of Haskell course + Type Level Programming

Lecture 8: Summary of Haskell course + Type Level Programming Lecture 8: Summary of Haskell course + Type Level Programming Søren Haagerup Department of Mathematics and Computer Science University of Southern Denmark, Odense October 31, 2017 Principles from Haskell

More information

Universes. Universes for Data. Peter Morris. University of Nottingham. November 12, 2009

Universes. Universes for Data. Peter Morris. University of Nottingham. November 12, 2009 for Data Peter Morris University of Nottingham November 12, 2009 Introduction Outline 1 Introduction What is DTP? Data Types in DTP Schemas for Inductive Families 2 of Data Inductive Types Inductive Families

More information

Fully Generic Programming Over Closed Universes of Inductive- Recursive Types

Fully Generic Programming Over Closed Universes of Inductive- Recursive Types Portland State University PDXScholar Dissertations and Theses Dissertations and Theses Spring 6-6-2017 Fully Generic Programming Over Closed Universes of Inductive- Recursive Types Larry Diehl Portland

More information

Inductive Types for Free

Inductive Types for Free Inductive Types for Free Representing Nested Inductive Types using W-types Michael Abbott (U. Leicester) Thorsten Altenkirch (U. Nottingham) Neil Ghani (U. Leicester) Inductive Types for Free p.1/22 Ideology

More information

GADTs. Wouter Swierstra and Alejandro Serrano. Advanced functional programming - Lecture 7. [Faculty of Science Information and Computing Sciences]

GADTs. Wouter Swierstra and Alejandro Serrano. Advanced functional programming - Lecture 7. [Faculty of Science Information and Computing Sciences] GADTs Advanced functional programming - Lecture 7 Wouter Swierstra and Alejandro Serrano 1 Today s lecture Generalized algebraic data types (GADTs) 2 A datatype data Tree a = Leaf Node (Tree a) a (Tree

More information

GADTs. Alejandro Serrano. AFP Summer School. [Faculty of Science Information and Computing Sciences]

GADTs. Alejandro Serrano. AFP Summer School. [Faculty of Science Information and Computing Sciences] GADTs AFP Summer School Alejandro Serrano 1 Today s lecture Generalized algebraic data types (GADTs) 2 A datatype data Tree a = Leaf Node (Tree a) a (Tree a) This definition introduces: 3 A datatype data

More information

Type-indexed functions in Generic Haskell

Type-indexed functions in Generic Haskell Type-indexed functions in Generic Haskell Johan Jeuring September 15, 2004 Introduction Today I will talk about: a Types of polymorphism. b Type-indexed functions. c Dependencies. Read about b, and c in

More information

Programming with Math and Logic

Programming with Math and Logic .. Programming with Math and Logic an invitation to functional programming Ed Morehouse Wesleyan University The Plan why fp? terms types interfaces The What and Why of Functional Programming Computing

More information

GADTs. Wouter Swierstra. Advanced functional programming - Lecture 7. Faculty of Science Information and Computing Sciences

GADTs. Wouter Swierstra. Advanced functional programming - Lecture 7. Faculty of Science Information and Computing Sciences GADTs Advanced functional programming - Lecture 7 Wouter Swierstra 1 Today s lecture Generalized algebraic data types (GADTs) 2 A datatype data Tree a = Leaf Node (Tree a) a (Tree a) This definition introduces:

More information

Giving Haskell a Promotion

Giving Haskell a Promotion Giving Haskell a Promotion José Pedro Magalhães Joint work with Brent A. Yorgey Stephanie Weirich Julien Cretin Simon Peyton Jones Dimitrios Vytiniotis http://www.dreixel.net FP dag 2012, Universiteit

More information

IA014: Advanced Functional Programming

IA014: Advanced Functional Programming IA014: Advanced Functional Programming 8. GADT Generalized Algebraic Data Types (and type extensions) Jan Obdržálek obdrzalek@fi.muni.cz Faculty of Informatics, Masaryk University, Brno Motivation IA014

More information

Lightweight Invariants with Full Dependent Types

Lightweight Invariants with Full Dependent Types Chapter 29 Lightweight Invariants with Full Dependent Types Edwin Brady 1, Christoph Herrmann 1, Kevin Hammond 1 Category: Position Paper Abstract: Dependent types allow a programmer to express invariant

More information

Exercise 1 (2+2+2 points)

Exercise 1 (2+2+2 points) 1 Exercise 1 (2+2+2 points) The following data structure represents binary trees only containing values in the inner nodes: data Tree a = Leaf Node (Tree a) a (Tree a) 1 Consider the tree t of integers

More information

Many Holes in Hindley-Milner

Many Holes in Hindley-Milner Many Holes in Hindley-Milner Sam Lindley Laboratory for Foundations of Computer Science, University of Edinburgh Sam.Lindley@ed.ac.uk September 21, 2008 Plugging many-holed contexts : context(3) Plugging

More information

Idris: Implementing a Dependently Typed Programming Language

Idris: Implementing a Dependently Typed Programming Language Idris: Implementing a Dependently Typed Programming Language Edwin Brady University of St Andrews ecb10@st-andrews.ac.uk @edwinbrady Type Inference and Automated Proving, Dundee, 12th May 2015 1 / 25 Idris

More information

Vectors are records, too!

Vectors are records, too! Vectors are records, too! Jesper Cockx 1 Gaëtan Gilbert 2 Nicolas Tabareau 2 Matthieu Sozeau 2 1 Gothenburg University, Sweden 2 INRIA, France 21 June 2018 types most popular example 1 data V (A : Set)

More information

Functional Programming and Modeling

Functional Programming and Modeling Chapter 2 2. Functional Programming and Modeling 2.0 2. Functional Programming and Modeling 2.0 Overview of Chapter Functional Programming and Modeling 2. Functional Programming and Modeling 2.1 Overview

More information

Parametricity and Dependent Types

Parametricity and Dependent Types Parametricity and Dependent Types Jean-Philippe Bernardy Patrik Jansson Chalmers University of Technology and University of Gothenburg {bernardy,patrikj}@chalmers.se Ross Paterson City University London

More information

Lesson 11 Universal Types. Universal Types and System F

Lesson 11 Universal Types. Universal Types and System F Lesson 11 Universal Types 2/28 Chapter 23 Universal Types and System F Varieties of polymorphism System F Examples Basic properties Erasure Evaluation issues Parametricity Impredicativity Lesson 11: Universal

More information

Informatics 1 Functional Programming Lecture 9. Algebraic Data Types. Don Sannella University of Edinburgh

Informatics 1 Functional Programming Lecture 9. Algebraic Data Types. Don Sannella University of Edinburgh Informatics 1 Functional Programming Lecture 9 Algebraic Data Types Don Sannella University of Edinburgh Part I Algebraic types Everything is an algebraic type data Bool = False True data Season = Winter

More information

Theorem Proving Principles, Techniques, Applications Recursion

Theorem Proving Principles, Techniques, Applications Recursion NICTA Advanced Course Theorem Proving Principles, Techniques, Applications Recursion 1 CONTENT Intro & motivation, getting started with Isabelle Foundations & Principles Lambda Calculus Higher Order Logic,

More information

Generic Programming With Dependent Types: II

Generic Programming With Dependent Types: II Generic Programming With Dependent Types: II Generic Haskell in Agda Stephanie Weirich University of Pennsylvania March 2426, 2010 SSGIP Generic-Haskell style generic programming in Agda Dependently-typed

More information

Generic Constructors and Eliminators from Descriptions

Generic Constructors and Eliminators from Descriptions DRAFT Generic Constructors and Eliminators from Descriptions Type Theory as a Dependently Typed Internal DSL Larry Diehl Tim Sheard Portland State University {ldiehl,sheard}@cs.pdx.edu Abstract Dependently

More information

From natural numbers to the lambda calculus

From natural numbers to the lambda calculus From natural numbers to the lambda calculus Benedikt Ahrens joint work with Ralph Matthes and Anders Mörtberg Outline 1 About UniMath 2 Signatures and associated syntax Outline 1 About UniMath 2 Signatures

More information

Type checking by theorem proving in IDRIS

Type checking by theorem proving in IDRIS Type checking by theorem proving in IDRIS p. 1 Type checking by theorem proving in IDRIS Scottish Theorem Proving, 10th February 2012 ecb10@st-andrews.ac.uk University of St Andrews Edwin Brady Type checking

More information

Idris. Programming with Dependent Types. Edwin Brady University of St Andrews, Scotland,

Idris. Programming with Dependent Types. Edwin Brady University of St Andrews, Scotland, Idris Programming with Dependent Types Edwin Brady (ecb10@st-andrews.ac.uk) University of St Andrews, Scotland, UK @edwinbrady London Haskell User Group, 22nd January 2014 Runtime Error! Type Error! Introduction

More information

Type families and data kinds

Type families and data kinds Type families and data kinds AFP Summer School Wouter Swierstra 1 Today How do GADTs work? Kinds beyond * Programming with types 2 Calling functions on vectors Given two vectors xs : Vec a n and ys : Vec

More information

Ideas over terms generalization in Coq

Ideas over terms generalization in Coq Ideas over terms generalization in Coq Vincent Siles 1,2 LIX/INRIA/Ecole Polytechnique Palaiseau, France Abstract Coq is a tool that allows writing formal proofs and check their correctness in its underlying

More information

First-Class Type Classes

First-Class Type Classes First-Class Type Classes Matthieu Sozeau Joint work with Nicolas Oury LRI, Univ. Paris-Sud - Démons Team & INRIA Saclay - ProVal Project Gallium Seminar November 3rd 2008 INRIA Rocquencourt Solutions for

More information

Idris, a language with dependent types Extended Abstract

Idris, a language with dependent types Extended Abstract Idris, a language with dependent types Extended Abstract Edwin Brady School of Computer Science, University of St Andrews, St Andrews, Scotland. Email: eb@cs.st-andrews.ac.uk. Tel: +44-1334-463253, Fax:

More information

Nonuniform (Co)datatypes

Nonuniform (Co)datatypes Foundational Nonuniform (Co)datatypes for Higher-Order Logic Jasmin Blanchette Fabian Meier Andrei Popescu Dmitriy Traytel uniform datatype 'a list = Nil Cons 'a ('a list) 1 3 4 uniform datatype 'a list

More information

Coercion Quantification

Coercion Quantification Coercion Quantification Ningning Xie 1 Richard A. Eisenberg 2 22 Sept. 2018 Haskell Implementor s Workshop (HIW 18) 1 The University of Hong Kong 2 Bryn Mawr College 1 Motivation Motivation Our long-term

More information

Towards Reasoning about State Transformer Monads in Agda. Master of Science Thesis in Computer Science: Algorithm, Language and Logic.

Towards Reasoning about State Transformer Monads in Agda. Master of Science Thesis in Computer Science: Algorithm, Language and Logic. Towards Reasoning about State Transformer Monads in Agda Master of Science Thesis in Computer Science: Algorithm, Language and Logic Viet Ha Bui Department of Computer Science and Engineering CHALMERS

More information

CS 320: Concepts of Programming Languages

CS 320: Concepts of Programming Languages CS 320: Concepts of Programming Languages Wayne Snyder Computer Science Department Boston University Lecture 04: Basic Haskell Continued o Polymorphic Types o Type Inference with Polymorphism o Standard

More information

10 Years of Partiality and General Recursion in Type Theory

10 Years of Partiality and General Recursion in Type Theory 10 Years of Partiality and General Recursion in Type Theory Ana Bove Chalmers University of Technology DTP 10 July 9th 2010 Claims and Disclaims I know that I know nothing Socrates Ana Bove DTP 10 July

More information

Generic discrimination

Generic discrimination Generic discrimination Fritz Henglein henglein@diku.dk Department of Computer Science University of Copenhagen (DIKU) SSGEP, Oxford, 2015-07-06 Some simple problems Given a list of pointers, how many unique

More information

MoreIntro_annotated.v. MoreIntro_annotated.v. Printed by Zach Tatlock. Oct 04, 16 21:55 Page 1/10

MoreIntro_annotated.v. MoreIntro_annotated.v. Printed by Zach Tatlock. Oct 04, 16 21:55 Page 1/10 Oct 04, 16 21:55 Page 1/10 * Lecture 02 Infer some type arguments automatically. Set Implicit Arguments. Note that the type constructor for functions (arrow " >") associates to the right: A > B > C = A

More information

Programming in Omega Part 1. Tim Sheard Portland State University

Programming in Omega Part 1. Tim Sheard Portland State University Programming in Omega Part 1 Tim Sheard Portland State University Tim Sheard Computer Science Department Portland State University Portland, Oregon PSU PL Research at Portland State University The Programming

More information

Structures in Coq January 27th 2014

Structures in Coq January 27th 2014 MPRI 2-7-2 Proof assistants ~sozeau/teaching/mpri-2-7-2-270114.pdf! Structures in Coq January 27th 2014 Matthieu Sozeau! "r² project team! Inria Paris & PPS! matthieu.sozeau@inria.fr! www.pps /~sozeau

More information

EPIGRAM 1: a perspective on functional programming with dependent types

EPIGRAM 1: a perspective on functional programming with dependent types EPIGRAM 1: a perspective on functional programming with dependent types James McKinna, Radboud Universiteit Nijmegen james.mckinna@cs.ru.nl FP Dag, Utrecht, January 25, 2008 In samenwerking met: Conor

More information

Static Contract Checking for Haskell

Static Contract Checking for Haskell Static Contract Checking for Haskell Dana N. Xu INRIA France Work done at University of Cambridge Simon Peyton Jones Microsoft Research Cambridge Joint work with Koen Claessen Chalmers University of Technology

More information

Polymorphism and System-F (OV)

Polymorphism and System-F (OV) Polymorphism and System-F (OV) Theorie der Programmierung SoSe 2014 FAU the occurrence of something in several different forms Polymorphism? Polymorphic systems Type systems that allow a single piece of

More information

Proofs for free. Parametricity for dependent types. JEAN-PHILIPPE BERNARDY and PATRIK JANSSON

Proofs for free. Parametricity for dependent types. JEAN-PHILIPPE BERNARDY and PATRIK JANSSON JFP 22 (2): 107 152, 2012. c Cambridge University Press 2012 doi:10.1017/s0956796812000056 First published online 30 March 2012 107 Proofs for free Parametricity for dependent types JEAN-PHILIPPE BERNARDY

More information

Exercise 1 ( = 24 points)

Exercise 1 ( = 24 points) 1 Exercise 1 (4 + 5 + 4 + 6 + 5 = 24 points) The following data structure represents polymorphic binary trees that contain values only in special Value nodes that have a single successor: data Tree a =

More information

Programming Languages 3. Definition and Proof by Induction

Programming Languages 3. Definition and Proof by Induction Programming Languages 3. Definition and Proof by Induction Shin-Cheng Mu Oct. 22, 2015 Total Functional Programming The next few lectures concerns inductive definitions and proofs of datatypes and programs.

More information

From Types to Contracts

From Types to Contracts From Types to Contracts head [] = BAD head (x:xs) = x head :: [a] -> a (head 1) Bug! Type BAD means should not happen: crash null :: [a] - > Bool null [] = True null (x:xs) = False head {xs not (null xs)}

More information

Talen en Compilers. Jurriaan Hage , period 2. November 13, Department of Information and Computing Sciences Utrecht University

Talen en Compilers. Jurriaan Hage , period 2. November 13, Department of Information and Computing Sciences Utrecht University Talen en Compilers 2017-2018, period 2 Jurriaan Hage Department of Information and Computing Sciences Utrecht University November 13, 2017 1. Introduction 1-1 This lecture Introduction Course overview

More information

PROGRAMMING IN HASKELL. CS Chapter 6 - Recursive Functions

PROGRAMMING IN HASKELL. CS Chapter 6 - Recursive Functions PROGRAMMING IN HASKELL CS-205 - Chapter 6 - Recursive Functions 0 Introduction As we have seen, many functions can naturally be defined in terms of other functions. factorial :: Int Int factorial n product

More information

Overloading, Type Classes, and Algebraic Datatypes

Overloading, Type Classes, and Algebraic Datatypes Overloading, Type Classes, and Algebraic Datatypes Delivered by Michael Pellauer Arvind Computer Science and Artificial Intelligence Laboratory M.I.T. September 28, 2006 September 28, 2006 http://www.csg.csail.mit.edu/6.827

More information

SOFTWARE VERIFICATION AND COMPUTER PROOF (lesson 1) Enrico Tassi Inria Sophia-Antipolis

SOFTWARE VERIFICATION AND COMPUTER PROOF (lesson 1) Enrico Tassi Inria Sophia-Antipolis SOFTWARE VERIFICATION AND COMPUTER PROOF (lesson 1) Enrico Tassi Inria Sophia-Antipolis Who am I? 1. I'm a researcher at Inria 2. I work on proof assistants, the kind of tools that we will be using for

More information

Depending on Types. Stephanie Weirich University of Pennsylvania

Depending on Types. Stephanie Weirich University of Pennsylvania Depending on Types Stephanie Weirich University of Pennsylvania TDD Type- Driven Development with Dependent Types The Agda Experience On 2012-01- 11 03:36, Jonathan Leivent wrote on the Agda mailing list:

More information

Combining Programming with Theorem Proving

Combining Programming with Theorem Proving Combining Programming with Theorem Proving Chiyan Chen and Hongwei Xi Boston University Programming with Theorem Proving p.1/27 Motivation for the Research To support advanced type systems for practical

More information

Type Theory. Lecture 2: Dependent Types. Andreas Abel. Department of Computer Science and Engineering Chalmers and Gothenburg University

Type Theory. Lecture 2: Dependent Types. Andreas Abel. Department of Computer Science and Engineering Chalmers and Gothenburg University Type Theory Lecture 2: Dependent Types Andreas Abel Department of Computer Science and Engineering Chalmers and Gothenburg University Type Theory Course CM0859 (2017-1) Universidad EAFIT, Medellin, Colombia

More information

Programming Up-to-Congruence, Again. WG 2.8 Estes Park

Programming Up-to-Congruence, Again. WG 2.8 Estes Park Programming Up-to-Congruence, Again Stephanie Weirich University of Pennsylvania August 12, 2014 WG 2.8 Estes Park Zombie A functional programming language with a dependent type system intended for lightweight

More information

PROGRAMMING IN HASKELL. Chapter 5 - List Comprehensions

PROGRAMMING IN HASKELL. Chapter 5 - List Comprehensions PROGRAMMING IN HASKELL Chapter 5 - List Comprehensions 0 Set Comprehensions In mathematics, the comprehension notation can be used to construct new sets from old sets. {x 2 x {1...5}} The set {1,4,9,16,25}

More information

Recap from last time. Programming Languages. CSE 130 : Fall Lecture 3: Data Types. Put it together: a filter function

Recap from last time. Programming Languages. CSE 130 : Fall Lecture 3: Data Types. Put it together: a filter function CSE 130 : Fall 2011 Recap from last time Programming Languages Lecture 3: Data Types Ranjit Jhala UC San Diego 1 2 A shorthand for function binding Put it together: a filter function # let neg = fun f

More information

ABriefOverviewofAgda A Functional Language with Dependent Types

ABriefOverviewofAgda A Functional Language with Dependent Types ABriefOverviewofAgda A Functional Language with Dependent Types Ana Bove, Peter Dybjer, and Ulf Norell e-mail: {bove,peterd,ulfn}@chalmers.se Chalmers University of Technology, Gothenburg, Sweden Abstract.

More information

Programming with dependent types: passing fad or useful tool?

Programming with dependent types: passing fad or useful tool? Programming with dependent types: passing fad or useful tool? Xavier Leroy INRIA Paris-Rocquencourt IFIP WG 2.8, 2009-06 X. Leroy (INRIA) Dependently-typed programming 2009-06 1 / 22 Dependent types In

More information

Faith, Evolution, and Programming Languages. Philip Wadler University of Edinburgh

Faith, Evolution, and Programming Languages. Philip Wadler University of Edinburgh Faith, Evolution, and Programming Languages Philip Wadler University of Edinburgh Evolution Multiculturalism Part I Church: The origins of faith Gerhard Gentzen (1909 1945) Gerhard Gentzen (1935) Natural

More information

Embedded Domain Specific Language Implementation using Dependent Types

Embedded Domain Specific Language Implementation using Dependent Types Embedded Domain Specific Language Implementation using Dependent Types Edwin Brady eb@cs.st-andrews.ac.uk University of St Andrews GPCE/SLE, Eindhoven, 10/10/10 GPCE/SLE, Eindhoven, 10/10/10 p.1/36 Introduction

More information

Coq Summer School, Session 2 : Basic programming with numbers and lists. Pierre Letouzey

Coq Summer School, Session 2 : Basic programming with numbers and lists. Pierre Letouzey Coq Summer School, Session 2 : Basic programming with numbers and lists Pierre Letouzey Predened data structures Predened types are actually declared to Coq at load time 1 : Inductive bool := true false.

More information

Compiling Exceptions Correctly

Compiling Exceptions Correctly Compiling Exceptions Correctly Graham Hutton and Joel Wright School of Computer Science and IT University of Nottingham, United Kingdom Abstract. Exceptions are an important feature of modern programming

More information

COMP 3141 Software System Design and Implementation

COMP 3141 Software System Design and Implementation Student Number: Family Name: Given Names: Signature: THE UNIVERSITY OF NEW SOUTH WALES Sample Exam 2018 Session 1 COMP 3141 Software System Design and Implementation Time allowed: 2 hours, plus 10 minutes

More information

An Algebra of Dependent Data Types

An Algebra of Dependent Data Types An Algebra of Dependent Data Types TYPES 2006 Tyng-Ruey Chuang Joint work with Jan-Li Lin Institute of Information Science, Academia Sinica Nangang, Taipei 115, Taiwan trc@iis.sinica.edu.tw 1 List in Coq

More information

CMSC 330: Organization of Programming Languages. Functional Programming with Lists

CMSC 330: Organization of Programming Languages. Functional Programming with Lists CMSC 330: Organization of Programming Languages Functional Programming with Lists CMSC330 Spring 2018 1 Lists in OCaml The basic data structure in OCaml Lists can be of arbitrary length Implemented as

More information

Refinements for free! 1

Refinements for free! 1 Refinements for free! Refinements for free! 1 Cyril Cohen joint work with Maxime Dénès and Anders Mörtberg University of Gothenburg and Inria Sophia-Antipolis May 8, 2014 1 This work has been funded by

More information

CSCE 314 Programming Languages

CSCE 314 Programming Languages CSCE 314 Programming Languages Haskell: Higher-order Functions Dr. Hyunyoung Lee 1 Higher-order Functions A function is called higher-order if it takes a function as an argument or returns a function as

More information

Graphical Untyped Lambda Calculus Interactive Interpreter

Graphical Untyped Lambda Calculus Interactive Interpreter Graphical Untyped Lambda Calculus Interactive Interpreter (GULCII) Claude Heiland-Allen https://mathr.co.uk mailto:claude@mathr.co.uk Edinburgh, 2017 Outline Lambda calculus encodings How to perform lambda

More information

Algebra of Programming using Dependent Types

Algebra of Programming using Dependent Types Algebra of Programming using Dependent Types Shin-Cheng Mu 1, Hsiang-Shang Ko 2, and Patrik Jansson 3 1 Institute of Information Science, Academia Sinica, Taiwan 2 Department of Computer Science and Information

More information

Extended Static Checking for Haskell (ESC/Haskell)

Extended Static Checking for Haskell (ESC/Haskell) Extended Static Checking for Haskell (ESC/Haskell) Dana N. Xu University of Cambridge advised by Simon Peyton Jones Microsoft Research, Cambridge Program Errors Give Headache! Module UserPgm where f ::

More information

CS 360: Programming Languages Lecture 10: Introduction to Haskell

CS 360: Programming Languages Lecture 10: Introduction to Haskell CS 360: Programming Languages Lecture 10: Introduction to Haskell Geoffrey Mainland Drexel University Thursday, February 5, 2015 Adapted from Brent Yorgey s course Introduction to Haskell. Section 1 Administrivia

More information

Expr_annotated.v. Expr_annotated.v. Printed by Zach Tatlock

Expr_annotated.v. Expr_annotated.v. Printed by Zach Tatlock Oct 05, 16 8:02 Page 1/14 * Lecture 03 Include some useful libraries. Require Import Bool. Require Import List. Require Import String. Require Import ZArith. Require Import Omega. List provides the cons

More information

Bag Equivalence via a Proof-Relevant Membership Relation

Bag Equivalence via a Proof-Relevant Membership Relation Bag Equivalence via a Proof-Relevant Membership Relation Nils Anders Danielsson Chalmers University of Technology and University of Gothenburg Abstract. Two lists are bag equivalent if they are permutations

More information

Adam Chlipala University of California, Berkeley ICFP 2006

Adam Chlipala University of California, Berkeley ICFP 2006 Modular Development of Certified Program Verifiers with a Proof Assistant Adam Chlipala University of California, Berkeley ICFP 2006 1 Who Watches the Watcher? Program Verifier Might want to ensure: Memory

More information

Libraries for Generic Programming in Haskell

Libraries for Generic Programming in Haskell Libraries for Generic Programming in Haskell Johan Jeuring Sean Leather José Pedro Magalhães Alexey Rodriguez Yakushev Technical Report UU-CS-2008-025 June 2009 Department of Information and Computing

More information

Programming with Ornaments

Programming with Ornaments Under consideration for publication in J. Functional Programming 1 Programming with Ornaments HSIANG-SHANG KO National Institute of Informatics, Japan JEREMY GIBBONS University of Oxford, UK Abstract Dependently

More information

Pierce Ch. 3, 8, 11, 15. Type Systems

Pierce Ch. 3, 8, 11, 15. Type Systems Pierce Ch. 3, 8, 11, 15 Type Systems Goals Define the simple language of expressions A small subset of Lisp, with minor modifications Define the type system of this language Mathematical definition using

More information

Shell CSCE 314 TAMU. Higher Order Functions

Shell CSCE 314 TAMU. Higher Order Functions 1 CSCE 314: Programming Languages Dr. Dylan Shell Higher Order Functions 2 Higher-order Functions A function is called higher-order if it takes a function as an argument or returns a function as a result.

More information

Exploring Lightweight Implementations of Generics. University of Oxford Page 1

Exploring Lightweight Implementations of Generics. University of Oxford Page 1 Exploring Lightweight Implementations of Generics Bruno Oliveira University of Oxford Page 1 Introduction Generic Programming is about defining functions that can work on a family of datatypes independently

More information

TYPE INFERENCE. François Pottier. The Programming Languages Mentoring ICFP August 30, 2015

TYPE INFERENCE. François Pottier. The Programming Languages Mentoring ICFP August 30, 2015 TYPE INFERENCE François Pottier The Programming Languages Mentoring Workshop @ ICFP August 30, 2015 What is type inference? What is the type of this OCaml function? let f verbose msg = if verbose then

More information

CSC324 Principles of Programming Languages

CSC324 Principles of Programming Languages CSC324 Principles of Programming Languages http://mcs.utm.utoronto.ca/~324 November 21, 2018 Last Class Types terminology Haskell s type system Currying Defining types Value constructors Algebraic data

More information

MoreIntro.v. MoreIntro.v. Printed by Zach Tatlock. Oct 07, 16 18:11 Page 1/10. Oct 07, 16 18:11 Page 2/10. Monday October 10, 2016 lec02/moreintro.

MoreIntro.v. MoreIntro.v. Printed by Zach Tatlock. Oct 07, 16 18:11 Page 1/10. Oct 07, 16 18:11 Page 2/10. Monday October 10, 2016 lec02/moreintro. Oct 07, 16 18:11 Page 1/10 * Lecture 02 Set Implicit Arguments. Inductive list (A: Type) : Type := nil : list A cons : A > list A > list A. Fixpoint length (A: Type) (l: list A) : nat := nil _ => O cons

More information

Inductive data types

Inductive data types Inductive data types Assia Mahboubi 9 juin 2010 In this class, we shall present how Coq s type system allows us to define data types using inductive declarations. Generalities Inductive declarations An

More information

CS 320: Concepts of Programming Languages

CS 320: Concepts of Programming Languages CS 320: Concepts of Programming Languages Wayne Snyder Computer Science Department Boston University Lecture 03: Bare-Bones Haskell Continued: o Function Application = Rewriting by Pattern Matching o Haskell

More information

Witnessing Purity, Constancy and Mutability APLAS Ben Lippmeier Australian National University 2009/12/14

Witnessing Purity, Constancy and Mutability APLAS Ben Lippmeier Australian National University 2009/12/14 Witnessing Purity, Constancy and Mutability APLAS 2009 Ben Lippmeier Australian National University 2009/12/14 The hidden cost of state monads map :: (a -> b) -> List a -> List b map f xs = case xs of

More information

Advanced features of Functional Programming (Haskell)

Advanced features of Functional Programming (Haskell) Advanced features of Functional Programming (Haskell) Polymorphism and overloading January 10, 2017 Monomorphic and polymorphic types A (data) type specifies a set of values. Examples: Bool: the type of

More information

Dependent types and program equivalence. Stephanie Weirich, University of Pennsylvania with Limin Jia, Jianzhou Zhao, and Vilhelm Sjöberg

Dependent types and program equivalence. Stephanie Weirich, University of Pennsylvania with Limin Jia, Jianzhou Zhao, and Vilhelm Sjöberg Dependent types and program equivalence Stephanie Weirich, University of Pennsylvania with Limin Jia, Jianzhou Zhao, and Vilhelm Sjöberg Doing dependent types wrong without going wrong Stephanie Weirich,

More information

Informatics 1 Functional Programming Lecture 11. Data Representation. Don Sannella University of Edinburgh

Informatics 1 Functional Programming Lecture 11. Data Representation. Don Sannella University of Edinburgh Informatics 1 Functional Programming Lecture 11 Data Representation Don Sannella University of Edinburgh Part I Complexity t = n vs t = n 2 10.4 9.6 8.8 8 7.2 6.4 5.6 4.8 4 3.2 2.4 1.6 0.8 0 0.8 1.6 2.4

More information

Haskell-style type classes with Isabelle/Isar

Haskell-style type classes with Isabelle/Isar = Isabelle λ β Isar α Haskell-style type classes with Isabelle/Isar Florian Haftmann 8 October 2017 Abstract This tutorial introduces Isar type classes, which are a convenient mechanism for organizing

More information

CIS 500: Software Foundations

CIS 500: Software Foundations CIS 500: Software Foundations Midterm I October 2, 2018 Name (printed): Username (PennKey login id): My signature below certifies that I have complied with the University of Pennsylvania s Code of Academic

More information