Advanced Type System Features Tom Schrijvers. Leuven Haskell User Group


 Reynold Copeland
 7 months ago
 Views:
Transcription
1 Advanced Type System Features Tom Schrijvers Leuven Haskell User Group
2 Data Recursion Genericity Schemes Expression Problem Monads GADTs DSLs Type Type Families Classes Lists and Effect Free Other Handlers Theorems Monoids
3 Data Recursion Genericity Schemes Expression Problem Monads GADTs GADTS DSLs Type Type Families Classes Lists and Effect Free Other Handlers Theorems Monoids
4 Static Type System
5 Static Type System Lightweight specifications Verified / enforced by the type checker
6 Static Type System
7 Static Type System Rules out many invalid programs
8 Static Type System Rules out many invalid programs Rules out some valid programs
9 Advanced Type Systems accept more valid programs accept fewer invalid programs
10 Advanced Type Systems accept more valid programs Java 5 generics Java 4 accept fewer invalid programs
11 A Problem with Expressions
12 Expressions data Exp = ILit Int Add Exp Exp eval :: Exp > Int eval (ILit n) = n eval (Add e1 e2) = eval e1 + eval e2
13 More Expressions data Exp = ILit Int Add Exp Exp BLit Bool
14 Revised Evaluator eval :: Exp > Int eval (ILit n) = n eval (Add e1 e2) = eval e1 + eval e2 eval (BLit b) = b
15 Revised Evaluator eval :: Exp > Int eval (ILit n) = n eval (Add e1 e2) = eval e1 + eval e2 eval (BLit b) = b
16 Revised Evaluator data Val = IVal Int BVal Bool eval :: Exp > Val eval (ILit n) = n eval (Add e1 e2) = eval e1 + eval e2 eval (BLit b) = b
17 Revised Evaluator data Val = IVal Int BVal Bool eval :: Exp > Val eval (ILit n) = n eval (Add e1 e2) = eval e1 + eval e2 eval (BLit b) = b
18 Revised Evaluator data Val = IVal Int BVal Bool eval :: Exp > Val eval (ILit n) = IVal n eval (Add e1 e2) = IVal (eval e1 + eval e2) eval (BLit b) = BVal b
19 Revised Evaluator data Val = IVal Int BVal Bool eval :: Exp > Val eval (ILit n) = IVal n eval (Add e1 e2) = IVal (eval e1 + eval e2) eval (BLit b) = BVal b
20 Revised Evaluator data Val = IVal Int BVal Bool eval :: Exp > Val eval (ILit n) = IVal n eval (Add e1 e2) = case (eval e1, eval e2) of (IVal n1, IVal n2) > IVal (n1+n2) eval (BLit b) = BVal b
21 Revised Evaluator data Val = IVal Int BVal Bool eval :: Exp > Val eval (ILit n) = IVal n eval (Add e1 e2) = case (eval e1, eval e2) of (IVal n1, IVal n2) > IVal (n1+n2) _ >??? eval (BLit b) = BVal b
22 Revised Evaluator data Val = IVal Int BVal Bool eval :: Exp > Maybe Val eval (ILit n) = IVal n eval (Add e1 e2) = case (eval e1, eval e2) of (IVal n1, IVal n2) > IVal (n1+n2) _ > Nothing eval (BLit b) = BVal b
23 Revised Evaluator data Val = IVal Int BVal Bool eval :: Exp > Maybe Val eval (ILit n) = IVal n eval (Add e1 e2) = case (eval e1, eval e2) of (IVal n1, IVal n2) > IVal (n1+n2) _ > Nothing eval (BLit b) = BVal b
24 Revised Evaluator data Val = IVal Int BVal Bool eval :: Exp > Maybe Val eval (ILit n) = Just (IVal n) eval (Add e1 e2) = case (eval e1, eval e2) of (IVal n1, IVal n2) > Just (IVal (n1+n2)) _ > Nothing eval (BLit b) = Just (BVal b)
25 Revised Evaluator data Val = IVal Int BVal Bool eval :: Exp > Maybe Val eval (ILit n) = Just (IVal n) eval (Add e1 e2) = case (eval e1, eval e2) of (IVal n1, IVal n2) > Just (IVal (n1+n2)) _ > Nothing eval (BLit b) = Just (BVal b)
26 Revised Evaluator data Val = IVal Int BVal Bool eval :: Exp > Maybe Val eval (ILit n) = Just (IVal n) eval (Add e1 e2) = case (eval e1, eval e2) of (Just (IVal n1), Just (IVal n2)) > Just (IVal (n1+n2)) _ > Nothing eval (BLit b) = Just (BVal b)
27 Revised Evaluator data Val = IVal Int BVal Bool eval :: Exp > Maybe Val eval (ILit n) = Just (IVal n) eval (Add e1 e2) Overhead due to possibly illtyped expressions = case (eval e1, eval e2) of (Just (IVal n1), Just (IVal n2)) > Just (IVal (n1+n2)) _ > Nothing eval (BLit b) = Just (BVal b)
28 GADTs to the Rescue
29 The Problem admits invalid values Exp
30 The Problem admits invalid values Exp Add (BLit True) (ILit 5)
31 The Problem accept more valid programs admits invalid values Exp accept fewer invalid programs
32 The Problem accept more valid programs admits invalid values Exp GADTs accept fewer invalid programs
33 The Problem accept more valid programs admits invalid values Exp Exp a GADTs accept fewer invalid programs
34 The Problem accept more valid programs admits invalid values Exp admits only valid values Exp a GADTs accept fewer invalid programs
35 Parametrised Expressions Exp a
36 Parametrised Expressions Expressions that yield a value of type a type a Exp a
37 Parametrised Expressions Expressions that yield a value of type a type a Exp a indexed family index
38 Parametrised Expressions Expressions that yield a value of type a type a Exp a indexed family index family members Exp Int Exp Bool
39 Parametrised Expressions Expressions that yield a value of type a type a Exp a indexed family index family members Exp Int Exp Bool ILit 0 Add (ILit 1) (ILit 2)
40 Parametrised Expressions Expressions that yield a value of type a type a Exp a indexed family index family members Exp Int ILit 0 Exp Bool BLit True Add (ILit 1) (ILit 2) BLit False
41 Generalized Algebraic Data Type data Exp where ILit :: Int > Exp Add :: Exp > Exp > Exp BLit :: Bool > Exp
42 Generalized Algebraic Data Type data Exp a where ILit :: Int > Exp Int Add :: Exp Int > Exp Int > Exp Int BLit :: Bool > Exp Bool
43 Generalized Algebraic Data Type indexed family data Exp a where ILit :: Int > Exp Int Add :: Exp Int > Exp Int > Exp Int BLit :: Bool > Exp Bool
44 Generalized Algebraic Data Type indexed family Refined index data Exp a where ILit :: Int > Exp Int Add :: Exp Int > Exp Int > Exp Int BLit :: Bool > Exp Bool
45 GADT Evaluator eval :: Exp a > a eval (ILit n) = n eval (Add e1 e2) = eval e1 + eval e2 eval (BLit b) = b
46 GADT Evaluator eval :: Exp a > a No noise due to possibly illtyped expressions! eval (ILit n) = n eval (Add e1 e2) = eval e1 + eval e2 eval (BLit b) = b
47 GADT Evaluator eval :: Exp a > a No noise due to possibly illtyped expressions! eval (ILit n) = n From the pattern match we know that a = Int eval (Add e1 e2) = eval e1 + eval e2 eval (BLit b) = b
48 GADT Evaluator eval :: Exp a > a No noise due to possibly illtyped expressions! eval (ILit n) = n From the pattern match we know that a = Int eval (Add e1 e2) = eval e1 + eval e2 eval (BLit b) = b From the pattern match we know that a = Bool
49 GADT Extension data Exp a where ILit :: Int > Exp Int Add :: Exp Int > Exp Int > Exp Int BLit :: Bool > Exp Bool IfThenElse :: Exp Bool > Exp a > Exp a > Exp a
50 Extended GADT Evaluator eval :: Exp a > a eval (ILit n) = n eval (Add e1 e2) = eval e1 + eval e2 eval (BLit b) = b eval (IfThenElse i t e) = if eval i then eval t else eval e
51 Alternative Syntax data Exp = ILit Int Add (Exp ) (Exp ) BLit Bool
52 Alternative Syntax data Exp a = a ~ Int => ILit Int a ~ Int => Add (Exp Int) (Exp Int) a ~ Bool => BLit Bool
53 Alternative Syntax data Exp a = a ~ Int => ILit Int a ~ Int => Add (Exp Int) (Exp Int) a ~ Bool => BLit Bool Equality Constraint
54 Alternative Syntax data Exp a = a ~ Int => ILit Int a ~ Int => Add (Exp Int) (Exp Int) a ~ Bool => BLit Bool Equality Constraint a ~ Int a equals Int
55 Ensure & Assume Construct value ILit n :: Exp a Type checker has to assure that a ~ Int
56 Ensure & Assume Construct value ILit n :: Exp a Type checker has to assure that a ~ Int Deconstruct value case e :: Exp a of ILit n > body Type checker can assume that a ~ Int
57 LengthIndexed Lists with GADTs
58 Regular Lists data List a = Nil Cons a (List a) head :: List a > a head (Cons x xs) = x
59 Regular Lists data List a = Nil Cons a (List a) head :: List a > a head (Cons x xs) = x
60 Regular Lists data List a = Nil Cons a (List a) head :: List a > a head (Cons x xs) = x crashes on empty list!
61 The Problem crashes on empty list head List a
62 The Problem crashes on empty list head List a head Nil
63 The Problem accept more valid programs crashes on empty list head List a accept fewer invalid programs
64 The Problem accept more valid programs crashes on empty list head List a GADTs accept fewer invalid programs
65 The Problem accept more valid programs crashes on empty list head List a head List n a GADTs accept fewer invalid programs
66 The Problem accept more valid programs crashes on empty list head List a does not accept head Nil head List n a GADTs accept fewer invalid programs
67 LengthIndexed Lists List n a
68 LengthIndexed Lists List n a indexed family index
69 LengthIndexed Lists List n a indexed family index family members List Z a List (S Z) a List (S (S Z)) a
70 LengthIndexed Lists List n a indexed family index family members List Z a List (S Z) a List (S (S Z)) a Nil Cons x Nil Cons x (Cons y)ni
71 LengthIndex List GADT data List a where Nil :: List a Cons :: a > List a > List a
72 LengthIndex List GADT data List n a where Nil :: List Z a Cons :: a > List n a > List (S n) a
73 LengthIndex List GADT indexed family data List n a where Nil :: List Z a Cons :: a > List n a > List (S n) a
74 LengthIndex List GADT indexed family Refined index data List n a where Nil :: List Z a Cons :: a > List n a > List (S n) a
75 LengthIndex List GADT indexed family Refined index data List n a where Nil :: List Z a Cons :: a > List n a > List (S n) a data Z data S n Empty data types: only used as type indices
76 Safe Head data List n a where Nil :: List Z a Cons :: a > List n a > List (S n) a head :: List a > a head (Cons x xs) = x
77 Safe Head data List n a where Nil :: List Z a Cons :: a > List n a > List (S n) a head :: List (S n) a > a head (Cons x xs) = x
78 Safe Head data List n a where Nil :: List Z a Cons :: a > List n a > List (S n) a head :: List (S n) a > a head (Cons x xs) = x > head Nil Couldn't match type Z with S n0 Expected type: List (S n0) a Actual type: List Z a In the first argument of head, namely Nil In the expression: head Nil
79 Safe Zip data List n a where Nil :: List Z a Cons :: a > List n a > List (S n) a zip :: List a > List b > List (a,b) zip Nil Nil = Nil zip (Cons x xs) (Cons y ys) = Cons (x,y) (zip xs ys) lists of different length!
80 Safe Zip data List n a where Nil :: List Z a Cons :: a > List n a > List (S n) a zip :: List n a > List n b > List n (a,b) zip Nil Nil = Nil zip (Cons x xs) (Cons y ys) = Cons (x,y) (zip xs ys)
81 Type Families
82 Append? data List n a where Nil :: List Z a Cons :: a > List n a > List (S n) a append :: List n a > List m a > List? a append Nil ys = ys append (Cons x xs) ys = Cons x (append xs ys)
83 Append? data List n a where Nil :: List Z a Cons :: a > List n a > List (S n) a append :: List n a > List m a > List? a append Nil ys n + m = ys append (Cons x xs) ys = Cons x (append xs ys)
84 Append? data List n a where Nil :: List Z a Cons :: a > List n a > List (S n) a append :: List n a > List m a > List? a append Nil ys n + m = ys append (Cons x xs) ys = Cons x (append xs ys) typelevel computation
85 The Problem append
86 The Problem accept more valid programs append accept fewer invalid programs
87 The Problem accept more valid programs Type Families append accept fewer invalid programs
88 The Problem accept more valid programs append Type Families append accept fewer invalid programs
89 Type Family aka Type Function type family Add n m where Add Z m = m Add (S n) m = S (Add n m)
90 Append with Type Family type family Add n m where Add Z m = m Add (S n) m = S (Add n m) append :: List n a > List m a > List (Add n m) a append Nil ys = ys append (Cons x xs) ys = Cons x (append xs ys)
91 Open & Associated Type Families
92 Collect Type Class class Collect c where insert :: c >? > c
93 Elem Type Family (open) type class declaration class Collect c where insert :: c > Elem c > c type family Elem c open type family declaration
94 Instances type class instance instance Collect [e] where insert l c = c : l type instance Elem [e] = e type family instance
95 Open Nature type instance Elem [e] = e instance Collect [e] where insert l c = c : l type instance Elem ByteString = Word8 instance Collect ByteString where insert l c = cons c l
96 Open Nature type instance Elem [e] = e instance Collect [e] where insert l c = c : l type instance Elem ByteString = Word8 instance Collect ByteString where insert l c = cons c l double instances
97 Associated Type Family class Collect c where type Elem c insert :: c > Elem c > c instance Collect [e] where type Elem [e] = e insert l c = c : l instance Collect ByteString where type Elem ByteString = Word8 insert l c = cons c l
98 Associated Type Family class Collect c where type Elem c insert :: c > Elem c > c instance Collect [e] where type Elem [e] = e insert l c = c : l instance Collect ByteString where type Elem ByteString = Word8 insert l c = cons c l
99 Summary
100 Advanced Type System Features Generalised Algebraic Data Types Typelevel Functions aka Type Families
101 Advanced Type System Features Generalised Algebraic Data Types Typelevel Functions aka Type Families accept more valid programs accept fewer invalid programs
102 More To Learn Existential Types Rankn Polymorphism Kinds: Type Promotion, Kind Polymorphism Type Classes: Functional Dependencies, Resolution Extensions ValueDependent Types (beyond Haskell)
103 Next time: 19/5/2015
104 Data Recursion Genericity Schemes Expression Problem Monads GADTs DSLs Type Type Families Classes Lists and Effect Free other Handlers Theorems Monoids
105 Data Recursion Genericity Schemes Expression Problem Monads GADTs DSLs Type Type Families Classes Lists Quattro Stagioni Effect Free Handlers Theorems other of Haskell Monoids and
106 Join the Google Group Leuven Haskell User Group
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 informationProgramming 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 informationAdvances in Programming Languages
T O Y H Advances in Programming Languages APL8: Multiparameter Type Classes, Constructor Classes Ian Stark School of Informatics The University of Edinburgh Thursday 4 February Semester 2 Week 4 E H U
More informationGADTs. GADTs in Haskell
GADTs GADTs in Haskell ADT vs GADT Algebraic Datatype Data List a = Nil Cons a (List a) Data Tree a b = Tip a Node (Tree a b) b Fork (Tree a b) (Tree a b) Note that types than can be expressed as an ADT
More informationShell CSCE 314 TAMU. Functions continued
1 CSCE 314: Programming Languages Dr. Dylan Shell Functions continued 2 Outline Defining Functions List Comprehensions Recursion 3 A Function without Recursion Many functions can naturally be defined in
More informationLecture 4: Higher Order Functions
Lecture 4: Higher Order Functions Søren Haagerup Department of Mathematics and Computer Science University of Southern Denmark, Odense September 26, 2017 HIGHER ORDER FUNCTIONS The order of a function
More information# true;;  : bool = true. # false;;  : bool = false 9/10/ // = {s (5, "hi", 3.2), c 4, a 1, b 5} 9/10/2017 4
Booleans (aka Truth Values) Programming Languages and Compilers (CS 421) Sasa Misailovic 4110 SC, UIUC https://courses.engr.illinois.edu/cs421/fa2017/cs421a # true;;  : bool = true # false;;  : bool
More informationWeek 5 Tutorial Structural Induction
Department of Computer Science, Australian National University COMP2600 / COMP6260 Formal Methods in Software Engineering Semester 2, 2016 Week 5 Tutorial Structural Induction You should hand in attempts
More informationOverloading, 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 informationPolymorphism Overview (1A) Young Won Lim 2/20/18
Polymorphism Overview (1A) Copyright (c) 20162017 Young W. Lim. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2
More informationTypes in Programming Languages Dynamic and Static Typing, Type Inference (CTM 2.8.3, EPL* 4) Abstract Data Types (CTM 3.7) Monads (GIH** 9)
Types in Programming Languages Dynamic and Static Typing, Type Inference (CTM 2.8.3, EPL* 4) Abstract Data Types (CTM 3.7) Monads (GIH** 9) Carlos Varela Rensselaer Polytechnic Institute September 23,
More informationBooleans (aka Truth Values) Programming Languages and Compilers (CS 421) Booleans and ShortCircuit Evaluation. Tuples as Values.
Booleans (aka Truth Values) Programming Languages and Compilers (CS 421) Elsa L Gunter 2112 SC, UIUC https://courses.engr.illinois.edu/cs421/fa2017/cs421d # true;;  : bool = true # false;;  : bool =
More informationConcepts of program design Exam January 31, 13:30 16:30
Concepts of program design 2016 2017 Exam January 31, 13:30 16:30 Name: Student number: Please read the following instructions carefully: Fill in your name and student number above. Be prepared to identify
More informationInformatics 1 Functional Programming Lecture 12. Data Abstraction. Don Sannella University of Edinburgh
Informatics 1 Functional Programming Lecture 12 Data Abstraction Don Sannella University of Edinburgh Part I Sets as lists without abstraction We will look again at our four ways of implementing sets.
More informationCSc 372. Comparative Programming Languages. 8 : Haskell Function Examples. Department of Computer Science University of Arizona
1/43 CSc 372 Comparative Programming Languages 8 : Haskell Function Examples Department of Computer Science University of Arizona collberg@gmail.com Copyright c 2013 Christian Collberg Functions over Lists
More informationLists. Michael P. Fourman. February 2, 2010
Lists Michael P. Fourman February 2, 2010 1 Introduction The list is a fundamental datatype in most functional languages. ML is no exception; list is a builtin ML type constructor. However, to introduce
More informationIntroduction to Functional Programming in Haskell 1 / 56
Introduction to Functional Programming in Haskell 1 / 56 Outline Why learn functional programming? The essence of functional programming What is a function? Equational reasoning Firstorder vs. higherorder
More informationTuples. CMSC 330: Organization of Programming Languages. Examples With Tuples. Another Example
CMSC 330: Organization of Programming Languages OCaml 2 Higher Order Functions Tuples Constructed using (e1,..., en) Deconstructed using pattern matching Patterns involve parens and commas, e.g., (p1,p2,
More informationHaskell Overloading (1) LiUFP2016: Lecture 8 Type Classes. Haskell Overloading (3) Haskell Overloading (2)
Haskell Overloading (1) LiUFP2016: Lecture 8 Type Classes Henrik Nilsson University of Nottingham, UK What is the type of (==)? E.g. the following both work: 1 == 2 a == b I.e., (==) can be used to compare
More informationWriting code that I'm not smart enough to write. A funny thing happened at Lambda Jam
Writing code that I'm not smart enough to write A funny thing happened at Lambda Jam Background "Let s make a lambda calculator" Rúnar Bjarnason Task: write an interpreter for the lambda calculus Lambda
More informationProgramming Languages Fall 2013
Programming Languages Fall 2013 Lecture 2: types Prof. Liang Huang huang@qc.cs.cuny.edu Recap of Lecture 1 functional programming vs. imperative programming basic Haskell syntax function definition lazy
More informationLightweight 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 informationAlgebraic data types. The case against null
Algebraic data types The case against null Motivation PL history (1970's) SML, OCaml, Haskell, Scala, F#, Rust, Swift Variants Null references Userdefined Types compound ("Dunedin", 120_000) : string
More informationIntroduction to Typed Racket. The plan: Racket Crash Course Typed Racket and PL Racket Differences with the text Some PL Racket Examples
Introduction to Typed Racket The plan: Racket Crash Course Typed Racket and PL Racket Differences with the text Some PL Racket Examples Getting started Find a machine with DrRacket installed (e.g. the
More informationIntro. Scheme Basics. scm> 5 5. scm>
Intro Let s take some time to talk about LISP. It stands for LISt Processing a way of coding using only lists! It sounds pretty radical, and it is. There are lots of cool things to know about LISP; if
More informationFunctional dependencies versus type families and beyond
Functional dependencies versus type families and beyond Martin Sulzmann National University of Singapore Joint work with Tom Schrijvers Functional dependencies versus type families and beyond p.1 What
More informationProgramming Languages
CSE 130 : Spring 2011 Programming Languages Lecture 3: Crash Course Ctd, Expressions and Types Ranjit Jhala UC San Diego A shorthand for function binding # let neg = fun f > fun x > not (f x); # let
More informationcs242 Kathleen Fisher Reading: Concepts in Programming Languages, Chapter 6 Thanks to John Mitchell for some of these slides.
cs242 Kathleen Fisher Reading: Concepts in Programming Languages, Chapter 6 Thanks to John Mitchell for some of these slides. We are looking for homework graders. If you are interested, send mail to cs242cs.stanford.edu
More informationINTRODUCTION TO HASKELL
INTRODUCTION TO HASKELL PRINCIPLES OF PROGRAMMING LANGUAGES Norbert Zeh Winter 2018 Dalhousie University 1/81 HASKELL: A PURELY FUNCTIONAL PROGRAMMING LANGUAGE Functions are firstclass values: Can be
More informationBegin at the beginning
Begin at the beginning Expressions (Syntax) Exectime Dynamic Values (Semantics) Compiletime Static Types 1. Programmer enters expression 2. ML checks if expression is welltyped Using a precise set of
More informationAdding GADTs to OCaml the direct approach
Adding GADTs to OCaml the direct approach Jacques Garrigue & Jacques Le Normand Nagoya University / LexiFi (Paris) https://sites.google.com/site/ocamlgadt/ Garrigue & Le Normand Adding GADTs to OCaml 1
More informationCS 360: Programming Languages Lecture 12: More Haskell
CS 360: Programming Languages Lecture 12: More Haskell Geoffrey Mainland Drexel University Adapted from Brent Yorgey s course Introduction to Haskell. Section 1 Administrivia Administrivia Homework 5 due
More informationINFOB3TC Solutions for the Exam
Department of Information and Computing Sciences Utrecht University INFOB3TC Solutions for the Exam Johan Jeuring Monday, 13 December 2010, 10:30 13:00 lease keep in mind that often, there are many possible
More informationHow does ML deal with +?
How does ML deal with +? Moscow ML version 2.00 (June 2000)  op +; > val it = fn : int * int > int  1 + 1; > val it = 2 : int  1.0 + 1.0; > val it = 2.0 : real  false + false;! Overloaded + cannot
More informationCS Lecture 5: Pattern Matching. Prof. Clarkson Fall Today s music: Puff, the Magic Dragon by Peter, Paul & Mary
CS 3110 Lecture 5: Pattern Matching Prof. Clarkson Fall 2014 Today s music: Puff, the Magic Dragon by Peter, Paul & Mary Review Features so far: variables, operators, let expressions, if expressions, functions
More informationMonad Background (3A) Young Won Lim 11/18/17
Copyright (c) 20162017 Young W. Lim. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later version published
More informationCSC324 TUTORIAL 5. Shems Saleh* *Some slides inspired by/based on Afsaneh Fazly s slides
CSC324 TUTORIAL 5 ML Shems Saleh* *Some slides inspired by/based on Afsaneh Fazly s slides Assignment 1 2 More questions were added Questions regarding the assignment? Starting ML Who am I? Shems Saleh
More informationIdris: Implementing a Dependently Typed Programming Language
Idris: Implementing a Dependently Typed Programming Language Edwin Brady University of St Andrews ecb10@standrews.ac.uk @edwinbrady Type Inference and Automated Proving, Dundee, 12th May 2015 1 / 25 Idris
More informationRecap 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 informationRefined typechecking with Stardust
Refined typechecking with Stardust Joshua Dunfield Carnegie Mellon University (current affiliation: McGill University) PLPV 2007 Freiburg, Germany 5 October 2007 1 Conventional Static Typing ML, Haskell,...
More informationProgramming in Omega Part 2. Tim Sheard Portland State University
Programming in Omega Part 2 Tim Sheard Portland State University Recall Introduce new kinds Use GADTs to build indexed data Indexed data can supports singleton types (Nat ) relationships between types
More informationAdvanced Functional Programming
Advanced Functional Programming Tim Sheard Polymorphism HindleyMilner Polymorphism Rank 2 polymorphism Tim Sheard 1 Polymorphism A function is polymorphic if it can work on any kind of argument. f x =
More informationAccurate Step Counting
Accurate Step Counting Catherine Hope and Graham Hutton School of Computer Science and IT University of Nottingham, UK {cvh,gmh}@cs.nott.ac.uk Abstract Starting with an evaluator for a language, an abstract
More informationGHCi: Getting started (1A) Young Won Lim 6/3/17
GHCi: Getting started (1A) Copyright (c) 20162017 Young W. Lim. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2
More informationLibraries for Generic Programming in Haskell
Libraries for Generic Programming in Haskell Johan Jeuring, Sean Leather, José PedroMagalhães, and Alexey Rodriguez Yakushev Universiteit Utrecht, The Netherlands Abstract. These lecture notes introduce
More information02157 Functional Programming Tagged values and Higherorder list functions
Tagged values and Higherorder list functions nsen 1 DTU Informatics, Technical University of Denmark Tagged values and Higherorder list functions MRH 27/09/2012 Part I: Disjoint Sets An Example A shape
More informationAbstract Types, Algebraic Types, and Type Classes
Informatics 1 Functional Programming Lectures 13 and 14 Monday 9 and Tuesday 10 November 2009 Abstract Types, Algebraic Types, and Type Classes Philip Wadler University of Edinburgh Reminders Tutorial
More informationRecap: ML s Holy Trinity
Recap: ML s Holy Trinity Expressions (Syntax) Exectime Dynamic Values (Semantics) Compiletime Static Types 1. Programmer enters expression 2. ML checks if expression is welltyped Using a precise set
More informationRecap. Recap. Ifthenelse expressions. Ifthenelse expressions. Ifthenelse expressions. Ifthenelse expressions
Recap Epressions (Synta) Compiletime Static Eectime Dynamic Types (Semantics) Recap Integers: +,,* floats: +,,* Booleans: =,
More informationScheme. Functional Programming. Lambda Calculus. CSC 4101: Programming Languages 1. Textbook, Sections , 13.7
Scheme Textbook, Sections 13.1 13.3, 13.7 1 Functional Programming Based on mathematical functions Take argument, return value Only function call, no assignment Functions are firstclass values E.g., functions
More informationIdris, 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.standrews.ac.uk. Tel: +441334463253, Fax:
More informationCSci 450: Org. of Programming Languages Overloading and Type Classes
CSci 450: Org. of Programming Languages Overloading and Type Classes H. Conrad Cunningham 27 October 2017 (after class) Contents 9 Overloading and Type Classes 1 9.1 Chapter Introduction.........................
More informationLecture 2: List algorithms using recursion and list comprehensions
Lecture 2: List algorithms using recursion and list comprehensions Søren Haagerup Department of Mathematics and Computer Science University of Southern Denmark, Odense September 12, 2017 Expressions, patterns
More informationCSCIGA Final Exam
CSCIGA 2110003  Final Exam Instructor: Thomas Wies Name: Sample Solution ID: You have 110 minutes time. There are 7 assignments and you can reach 110 points in total. You can solve the exercises directly
More informationPolymorphic lambda calculus Princ. of Progr. Languages (and Extended ) The University of Birmingham. c Uday Reddy
0602552 Princ. of Progr. Languages (and Extended ) The University of Birmingham Spring Semester 201617 School of Computer Science c Uday Reddy201617 Handout 6: Polymorphic Type Systems 1. Polymorphic
More informationCSC324 Functional Programming Typing, Exceptions in ML
CSC324 Functional Programming Typing, Exceptions in ML Afsaneh Fazly 1 Winter 2013 1 with many thanks to Anya Tafliovich, Gerald Penn, Sheila McIlraith, Wael Aboelsaddat, Tony Bonner, Eric Joanis, Suzanne
More informationHaskell Making Our Own Types and Typeclasses
Haskell Making Our Own Types and Typeclasses http://igm.univmlv.fr/~vialette/?section=teaching Stéphane Vialette LIGM, Université ParisEst MarnelaVallée January 13, 2015 Making Our Own Types and Typeclasses
More informationApplying TypeLevel and Generic Programming in Haskell
Summer School on Generic and Effectful Programming Applying TypeLevel and Generic Programming in Haskell Andres Löh, WellTyped LLP July 4, 2015 Contents 1 Introduction and typelevel programming 5 1.1
More informationTyping Data. Chapter Recursive Types Declaring Recursive Types
Chapter 27 Typing Data 27.1 Recursive Types 27.1.1 Declaring Recursive Types We saw in the previous lecture how rec was necessary to write recursive programs. But what about defining recursive types? Recursive
More information02157 Functional Programming. Michael R. Ha. Tagged values and Higherorder list functions. Michael R. Hansen
Tagged values and Higherorder list functions nsen 1 DTU Compute, Technical University of Denmark Tagged values and Higherorder list functions MRH 3/10/2017 Overview Disjoint union (or Tagged Values)
More informationMonads. Prof. Clarkson Fall Today s music: Vámanos Pal Monte by Eddie Palmieri
Monads Prof. Clarkson Fall 2017 Today s music: Vámanos Pal Monte by Eddie Palmieri Review Currently in 3110: Advanced topics Futures: Async: deferreds, return, bind Today: Monads Monad tutorials since
More informationSide note: Tail Recursion. Begin at the beginning. Side note: Tail Recursion. Base Types. Base Type: int. Base Type: int
Begin at the beginning Epressions (Synta) Compiletime Static Eectime Dynamic Types Values (Semantics) 1. Programmer enters epression 2. ML checks if epression is welltyped Using a precise set of rules,
More informationCSE 307: Principles of Programming Languages
1 / 63 CSE 307: Principles of Programming Languages Syntax R. Sekar Topics 1. Introduction 2. Basics 3. Functions 4. Data Structures 5. Overview 6. OCAML Performance 2 / 63 3 / 63 Section 1 Introduction
More informationCIS552: Advanced Programming
CIS552: Advanced Programming Handout 8 What is a Parser? A parser is a program that analyzes a piece of text to deine its structure (and, typically, returns a tree representing this structure). The World
More informationTail Recursion: Factorial. Begin at the beginning. How does it execute? Tail recursion. Tail recursive factorial. Tail recursive factorial
Begin at the beginning Epressions (Synta) Compiletime Static Eectime Dynamic Types Values (Semantics) 1. Programmer enters epression 2. ML checks if epression is welltyped Using a precise set of rules,
More informationCSE 307: Principles of Programming Languages
CSE 307: Principles of Programming Languages Syntax R. Sekar 1 / 63 Topics 1. Introduction 2. Basics 3. Functions 4. Data Structures 5. Overview 6. OCAML Performance 2 / 63 Section 1 Introduction 3 / 63
More informationFunctional Paradigm II
Processadors de Llenguatge II Functional Paradigm II Pratt A.7 Robert Harper s SML tutorial (Sec II) Rafael Ramirez Dep Tecnologia Universitat Pompeu Fabra UserDefined Types How to define the new type.
More informationTowards 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 informationProgramming Languages. Datatypes
Programming Languages Datatypes Review so far Expressions Values Types Many kinds of expressions: 1. Simple 2. Variables 3. Functions Review so far We ve seen some base types and values: Integers, Floats,
More informationL28: Advanced functional programming
L28: Advanced functional programming Exercise 2 Due on 8th March 2017 Submission instructions Your solutions for this exericse should be handed in to the Graduate Education Office by 4pm on the due date.
More informationUserDefined Algebraic Data Types
72 Static Semantics UserDefined Types UserDefined Algebraic Data Types An algebraic data type declaration has the general form: data cx T α 1... α k = K 1 τ 11... τ 1k1... K n τ n1... τ nkn introduces
More informationCSE 130 Programming Languages. Lecture 3: Datatypes. Ranjit Jhala UC San Diego
CSE 130 Programming Languages Lecture 3: Datatypes Ranjit Jhala UC San Diego News? PA #2 (coming tonight) Ocamltop issues? Pleas post questions to Piazza Recap: ML s Holy Trinity Expressions (Syntax)
More informationCoq 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 informationType system. Type theory. Haskell type system. EDAN40: Functional Programming Types and Type Classes (revisited)
Type system EDAN40: Functional Programming Types and Type Classes (revisited) Jacek Malec Dept. of Computer Science, Lund University, Sweden April 3rd, 2017 In programming languages, a type system is a
More informationNews. Programming Languages. Recap. Recap: Environments. Functions. of functions: Closures. CSE 130 : Fall Lecture 5: Functions and Datatypes
CSE 130 : Fall 2007 Programming Languages News PA deadlines shifted PA #2 now due 10/24 (next Wed) Lecture 5: Functions and Datatypes Ranjit Jhala UC San Diego Recap: Environments Phone book Variables
More informationList Processing in Ocaml
CS251 Programming Languages Handout # 14 Prof. Lyn Turbak February 2, 2007 Wellesley College List Processing in Ocaml Given a list of integers ns, suppose we want to return a new list of the same length
More informationPROGRAMMING IN HASKELL. Chapter 2  First Steps
PROGRAMMING IN HASKELL Chapter 2  First Steps 0 The Hugs System Hugs is an implementation of Haskell 98, and is the most widely used Haskell system; The interactive nature of Hugs makes it well suited
More informationMonad Background (3A) Young Won Lim 11/20/17
Copyright (c) 20162017 Young W. Lim. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later version published
More informationScheme: Data. CS F331 Programming Languages CSCE A331 Programming Language Concepts Lecture Slides Monday, April 3, Glenn G.
Scheme: Data CS F331 Programming Languages CSCE A331 Programming Language Concepts Lecture Slides Monday, April 3, 2017 Glenn G. Chappell Department of Computer Science University of Alaska Fairbanks ggchappell@alaska.edu
More informationSemantic Analysis. Outline. The role of semantic analysis in a compiler. Scope. Types. Where we are. The Compiler FrontEnd
Outline Semantic Analysis The role of semantic analysis in a compiler A laundry list of tasks Scope Static vs. Dynamic scoping Implementation: symbol tables Types Static analyses that detect type errors
More informationProgramming Languages
CSE 130 : Winter 2009 Programming Languages News PA 2 out, and due Mon 1/26 5pm Lecture 5: Functions and Datatypes t UC San Diego Recap: Environments Phone book Variables = names Values = phone number
More informationComp 311 Functional Programming. Eric Allen, Two Sigma Investments Robert Corky Cartwright, Rice University Sagnak Tasirlar, Two Sigma Investments
Comp 311 Functional Programming Eric Allen, Two Sigma Investments Robert Corky Cartwright, Rice University Sagnak Tasirlar, Two Sigma Investments How to Decide Between Structural and Generative Recursion
More informationInductive Data Types
Inductive Data Types LarsHenrik Eriksson Functional Programming 1 Original slides by Tjark Weber LarsHenrik Eriksson (UU) Inductive Data Types 1 / 42 Inductive Data Types Today Today New names for old
More informationEdward Kmett. Iteratees, Parsec, and Monoids A PARSING TRIFECTA
Edward Kmett Iteratees, Parsec, and Monoids A PARSING TRIFECTA Overview The Problem Deriving Iteratees á la Oleg Buffered Iteratees Layering Parsec Over Iteratees Local ContextSensitivity Monoids From
More informationCombining 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 informationFunctional Programming TDA 452, DIT 142
Chalmers Göteborgs Universitet 20180111 Examiner: Thomas Hallgren, D&IT, Answering questions at approx 15.00 (or by phone) Functional Programming TDA 452, DIT 142 20180111 14.00 18.00 Samhällsbyggnad
More informationTypes, Type Inference and Unification
Types, Type Inference and Unification Mooly Sagiv Slides by Kathleen Fisher and John Mitchell Cornell CS 6110 Summary (Functional Programming) Lambda Calculus Basic ML Advanced ML: Modules, References,
More informationProgramming Languages
What about more complex data? CSE 130 : Fall 2012 Programming Languages Expressions Values Lecture 3: Datatypes Ranjit Jhala UC San Diego Types Many kinds of expressions: 1. Simple 2. Variables 3. Functions
More informationFunctional programming with OCaml. Programming with OCaml. Fall Software Foundations CIS 500. OCaml and this course. Announcements. features.
CIS 500 Software Foundations Fall 2004 Programming with OCaml IS 500, Programming with OCaml 1 Functional programming with OCaml IS 500, Programming with OCaml 3 Announcements Homework 1 was due at noon.
More informationDocumentation for the Idris Language. Version 0.99
Documentation for the Idris Language Version 0.99 Contents 1 The Idris Tutorial 2 2 Frequently Asked Questions 61 3 The Effects Tutorial 66 4 Theorem Proving 98 5 Language Reference 109 6 Tutorials on
More informationAbstract Interpretation Using Laziness: Proving Conway s Lost Cosmological Theorem
Abstract Interpretation Using Laziness: Proving Conway s Lost Cosmological Theorem Kevin Watkins CMU CSD POP Seminar December 8, 2006 In partial fulfillment of the speaking skills requirement ? 2111 1231
More informationParametricity. Types Are Documentation. Tony Morris
Parametricity Types Are Documentation Tony Morris The Journey Fast and loose reasoning is morally correct Danielsson, Hughes, Jansson & Gibbons [DHJG06] tell us: Functional programmers often reason about
More informationTYPE 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 informationSpecifications. Prof. Clarkson Fall Today s music: Nice to know you by Incubus
Specifications Prof. Clarkson Fall 2015 Today s music: Nice to know you by Incubus Question Would you like a tiny bonus to your final grade for being here on time today? A. Yes B. Sí C. Hai D. Haan E.
More informationGeneral Computer Science (CH ) Fall 2016 SML Tutorial: Practice Problems
General Computer Science (CH08320101) Fall 2016 SML Tutorial: Practice Problems November 30, 2016 Abstract This document accompanies the traditional SML tutorial in GenCS. It contains a sequence of simple
More informationMonads seen so far: IO vs Gen
Monads David Sands Monads seen so far: IO vs Gen IO A Gen A Instructions to build a value of type A by interacting with the operating system Instructions to create a random value of type A Run by the ghc
More informationProgramming Paradigms, Fall 06
Programming Paradigms, Fall 06 Multiple Choice Exam January 29, 2007, 10:00 11:15 ID Name Each of the following questions has exactly one correct answer. For each question, you may select one or more answers
More informationType Systems. Parametric Polymorphism. 1. Recall LetPolymorphism. 1. Recall LetPolymorphism. Lecture 9 Dec. 15th, 2004 Sebastian Maneth
Today Parametric Polymorphism Type Systems Lecture 9 Dec. 15th, 2004 Sebastian Maneth 1. Recall LetPolymorphism 4. System Fsub 5. Properties of Fsub http://lampwww.epfl.ch/teaching/typesystems/2004
More informationLECTURE 3. Compiler Phases
LECTURE 3 Compiler Phases COMPILER PHASES Compilation of a program proceeds through a fixed series of phases. Each phase uses an (intermediate) form of the program produced by an earlier phase. Subsequent
More informationHomework 1: Functional Programming, Haskell
Com S 541 Programming Languages 1 September 25, 2005 Homework 1: Functional Programming, Haskell Due: problems 1 and 3, Thursday, September 1, 2005; problems 49, Thursday, September 15, 2005; remaining
More information