EECS 700 Functional Programming
|
|
- Cameron Maxwell
- 5 years ago
- Views:
Transcription
1 EECS 700 Functional Programming Dr. Andy Gill University of Kansas March 30, / 38
2 Jolt Awards Books (Technical) High Performance MySQL by Baron Schwartz, Peter Zaitsev, Vadim Tkachenko, Jeremy Zawodny, Arjen Lentz, Derek J. Balling (O Reilly Media) Java Power Tools by John Ferguson Smart (O Reilly Media) Programming in Scala by Martin Odersky, Lex Spoon, and Bill Venners (Artima Press) Real World Haskell by John Goerzen, Bryan O Sullivan, Donald Bruce Stewart (O Reilly Media) The iphone Developer s Cookbook: Building Applications with the iphone SDK by Erica Sadun (Addison-Wesley Professional) 2 / 38
3 Jolt Awards Books (Technical) High Performance MySQL by Baron Schwartz, Peter Zaitsev, Vadim Tkachenko, Jeremy Zawodny, Arjen Lentz, Derek J. Balling (O Reilly Media) Java Power Tools by John Ferguson Smart (O Reilly Media) Programming in Scala by Martin Odersky, Lex Spoon, and Bill Venners (Artima Press) Real World Haskell by John Goerzen, Bryan O Sullivan, Donald Bruce Stewart (O Reilly Media) The iphone Developer s Cookbook: Building Applications with the iphone SDK by Erica Sadun (Addison-Wesley Professional) 3 / 38
4 Domain Specific Languages Based on slides by Ulf Norell. I ed him asking permission: Ulf, I m teaching an AFP class here at Kansas, and really like the way you ve presented the concept of a DSL. Can I based my slides of your material? He replied: 4 / 38
5 Domain Specific Languages Based on slides by Ulf Norell. I ed him asking permission: Ulf, I m teaching an AFP class here at Kansas, and really like the way you ve presented the concept of a DSL. Can I based my slides of your material? He replied: Du har skickat ett brev till en epostadress som r under avveckling, vnligen se webbsidan nedan eller kontakta mottagaren fr att f rtt adress. Ditt brev har levererats till mottagaren. 5 / 38
6 Domain Specific Languages Based on slides by Ulf Norell. I ed him asking permission: Ulf, I m teaching an AFP class here at Kansas, and really like the way you ve presented the concept of a DSL. Can I based my slides of your material? He replied: Du har skickat ett brev till en epostadress som r under avveckling, vnligen se webbsidan nedan eller kontakta mottagaren fr att f rtt adress. Ditt brev har levererats till mottagaren. You have sent an to an address which is being phased out, please see the webpage below or contact the recipient to get the correct address. Your has been delivered to the recipient. 6 / 38
7 Domain Specific Languages We have seen several DSLs. All are libraries in Haskell. You need to know Haskell to use any Haskell-hosted DSL. 7 / 38
8 Domain Specific Languages - Anatomy User-code, written in the DSL are centered round a specific type (or types). There are ways of constructing this type, composing this type, running (or making observations about) this type. 8 / 38
9 Our Property DSL (==) :: (Eq a) => a -> a -> Bool ($) :: (a -> b) -> a -> b (==>) :: (Testable a) => Bool -> a -> Property label :: (Testable a) => String -> a -> Property classify :: (Testable a) => Bool -> String -> a -> Property forall :: (Show a, Testable b) => Gen a -> (a -> b) -> Property collect :: (Show a, Testable b) => a -> b -> Property collect a b = label (show a) b test :: (Testable a) => a -> IO () 9 / 38
10 Primitive vs Derived A primitive operation is defined exploiting the definitions of the involved types. A derived operation can be defined purely in terms of other operations. -- Primitive label :: (Testable a) => String -> a -> Property -- derivied collect :: (Show a, Testable b) => a -> b -> Property collect a b = label (show a) b 10 / 38
11 What to think about Compositionally Combining elements into more complex ones should be easy and natural. Abstraction The user shouldn t have to know (or be allowed to exploit) the underlying implementation of your types. (or changing implementation shouldn t break user code!) 11 / 38
12 Implementation of a DSEL Shallow embedding Represent elements by their semantics (what observations they support) Constructor functions and combinators do most of the work run function(s) are (almost) for free Deep embedding Represent elements by how they are constructed Most of the work done by the run function(s) Constructor functions and combinators for free Optimization opportunities (more later) 12 / 38
13 -- our principal type, Expr newtype Expr = Expr (Maybe Int) 13 / 38
14 -- our principal type, Expr newtype Expr = Expr (Maybe Int) -- our way of constructing Expr s lit :: Int -> Expr lit n = Expr (Just n) 14 / 38
15 -- our principal type, Expr newtype Expr = Expr (Maybe Int) -- our way of constructing Expr s lit :: Int -> Expr lit n = Expr (Just n) -- our way of composing Expr s plus :: Expr -> Expr -> Expr plus (Expr (Just v1)) (Expr (Just v2)) = Expr (Just (v1 + v2)) plus = Expr Nothing 15 / 38
16 -- our principal type, Expr newtype Expr = Expr (Maybe Int) -- our way of constructing Expr s lit :: Int -> Expr lit n = Expr (Just n) -- our way of composing Expr s plus :: Expr -> Expr -> Expr plus (Expr (Just v1)) (Expr (Just v2)) = Expr (Just (v1 + v2)) plus = Expr Nothing -- our way of running Expr s runexpr :: Expr -> Maybe Int runexpr (Expr v) = v 16 / 38
17 divide :: Expr -> Expr -> Expr divide (Expr (Just v1)) (Expr (Just v2)) v2 /= 0 = Expr (Just (v1 div v2)) divide = Expr Nothing *Main> runexpr (lit 1) 17 / 38
18 divide :: Expr -> Expr -> Expr divide (Expr (Just v1)) (Expr (Just v2)) v2 /= 0 = Expr (Just (v1 div v2)) divide = Expr Nothing *Main> runexpr (lit 1) Just 1 *Main> runexpr (lit 1 plus lit 2) 18 / 38
19 divide :: Expr -> Expr -> Expr divide (Expr (Just v1)) (Expr (Just v2)) v2 /= 0 = Expr (Just (v1 div v2)) divide = Expr Nothing *Main> runexpr (lit 1) Just 1 *Main> runexpr (lit 1 plus lit 2) Just 3 *Main> runexpr (lit 1 divide lit 2) 19 / 38
20 divide :: Expr -> Expr -> Expr divide (Expr (Just v1)) (Expr (Just v2)) v2 /= 0 = Expr (Just (v1 div v2)) divide = Expr Nothing *Main> runexpr (lit 1) Just 1 *Main> runexpr (lit 1 plus lit 2) Just 3 *Main> runexpr (lit 1 divide lit 2) Just 0 *Main> runexpr (lit 1 divide lit 0) 20 / 38
21 divide :: Expr -> Expr -> Expr divide (Expr (Just v1)) (Expr (Just v2)) v2 /= 0 = Expr (Just (v1 div v2)) divide = Expr Nothing *Main> runexpr (lit 1) Just 1 *Main> runexpr (lit 1 plus lit 2) Just 3 *Main> runexpr (lit 1 divide lit 2) Just 0 *Main> runexpr (lit 1 divide lit 0) Nothing 21 / 38
22 This is an API, implementation can be hidden. -- our principal type, Expr newtype Expr = / 38
23 This is an API, implementation can be hidden. -- our principal type, Expr newtype Expr = our way of constructing Expr s lit :: Int -> Expr 23 / 38
24 This is an API, implementation can be hidden. -- our principal type, Expr newtype Expr = our way of constructing Expr s lit :: Int -> Expr -- our way of composing Expr s plus :: Expr -> Expr -> Expr divide :: Expr -> Expr -> Expr 24 / 38
25 This is an API, implementation can be hidden. -- our principal type, Expr newtype Expr = our way of constructing Expr s lit :: Int -> Expr -- our way of composing Expr s plus :: Expr -> Expr -> Expr divide :: Expr -> Expr -> Expr -- our way of running Expr s runexpr :: Expr -> Maybe Int 25 / 38
26 Deep Embedding -- our principal type, Expr data Expr = Lit Int Plus Expr Expr Divide Expr Expr 26 / 38
27 Deep Embedding -- our principal type, Expr data Expr = Lit Int Plus Expr Expr Divide Expr Expr -- our way of constructing Expr s lit :: Int -> Expr lit n = Lit n 27 / 38
28 Deep Embedding -- our principal type, Expr data Expr = Lit Int Plus Expr Expr Divide Expr Expr -- our way of constructing Expr s lit :: Int -> Expr lit n = Lit n -- our way of composing Expr s plus :: Expr -> Expr -> Expr plus e1 e2 = Plus e1 e2 divide :: Expr -> Expr -> Expr divide e1 e2 = Divide e1 e2 28 / 38
29 runexpr :: Expr -> Maybe Int runexpr (Lit i) = Just i runexpr (Plus e1 e2) = case runexpr e1 of Nothing -> Nothing Just v1 -> case runexpr e2 of Nothing -> Nothing Just v2 -> Just (v1 + v2) runexpr (Divide e1 e2) = case runexpr e1 of Nothing -> Nothing Just v1 -> case runexpr e2 of Nothing -> Nothing Just v2 v2 == 0 -> Nothing otherwise -> Just (v1 div v2) 29 / 38
30 Implementation of a DSEL Shallow embedding Represent elements by their semantics (what observations they support) Constructor functions and combinators do most of the work run function(s) are (almost) for free Deep embedding Represent elements by how they are constructed Most of the work done by the run function(s) Constructor functions and combinators for free Optimization opportunities (more later) 30 / 38
31 A Language for Shapes Step 1: Design the interface (or API) data Shape -- Constructor functions empty :: Shape circle :: Shape -- unit circle square :: Shape -- unit square -- Combinators translate :: Vec -> Shape -> Shape scale :: Vec -> Shape -> Shape rotate :: Angle -> Shape -> Shape union :: Shape -> Shape -> Shape intersect :: Shape -> Shape -> Shape difference :: Shape -> Shape -> Shape -- Run functions inside :: Point -> Shape -> Bool 31 / 38
32 Interface, continued Think about primitive/derived operations No obvious derived operations Sometimes introducing additional primitives makes the language nicer invert :: Shape -> Shape transform :: Matrix -> Shape -> Shape scale :: Vec -> Shape -> Shape scale v = transform (matrix (vecx v) 0 0 (vecy v)) rotate :: Angle -> Shape -> Shape rotate a = transform (matrix (cos a) (-sin a) (sin a) (cos a)) difference :: Shape -> Shape -> Shape difference a b = a intersect invert b 32 / 38
33 Shallow embedding What are the observations we can make of a shape? inside :: Point -> Shape -> Bool So, lets go for newtype Shape = Shape (Point -> Bool) inside :: Point -> Shape -> Bool inside p (Shape f) = f p In general, its not this easy. In most cases you need to generalize the type of the internal function a little to get a compositional shallow embedding. 33 / 38
34 Shallow embedding, continued If we picked the right implementation the operations should now be easy to implement. empty = Shape $ \p -> False circle = Shape $ \p -> ptx p ^ 2 + pty p ^ 2 <= 1 square = Shape $ \p -> abs (ptx p) <= 1 && abs (pty p) <= 1 transform m a = Shape $ \p -> mulpt (inv m) p inside a translate v a = Shape $ \p -> subtract p v inside a union a b = Shape $ \p -> inside p a inside p b intersect a b = Shape $ \p -> inside p a && inside p b invert a = Shape $ \p -> not (inside p a) 34 / 38
35 Deep embedding Representation is easy, just make a datatype of the primitive operations. data Shape = Empty Circle Square Translate Vec Shape Transform Matrix Shape Union Shape Shape Intersect Shape Shape Invert Shape empty circle translate transform union intersect invert = Empty = Circle = Translate = Transform = Union = Intersect = Invert 35 / 38
36 Deep embedding, continued All the work happens in the run function. inside :: Point -> Shape -> Bool p inside Empty = False p inside Circle = ptx p ^ 2 + pty p ^ 2 <= 1 p inside Square = abs (ptx p) <= 1 && abs (pty p) <= p inside Translate v a = subtract p v inside a p inside Transform m a = mulpt (inv m) p inside a p inside Union a b = inside p a inside p b p inside Intersect a b = inside p a && inside p b p inside Invert a = not (inside p a) 36 / 38
37 Example DSL: Chalkboard... $ fmap (choose green white) $ rotate 0.05 $ scale 50 $ checker 37 / 38
38 Example DSL: Chalkboard... $ stack $ [ fmap (choose (withalpha 0.8 col) (transparent white)) $ functionline (\ x -> (x * 400,t + 80 * x * sin (x * t))) 3 count (col,t) <- zip [red,green,blue] [16,18,20] ] ++ [ fmap (choose (withalpha 0.8 col) (transparent white)) $ functionline (\ x -> (400 - x * 400,t - 80 * x * sin (x * t))) 3 count (col,t) <- zip [cyan,purple,yellow] [15,17,20] ] ++ [ pure (alpha white) ] 38 / 38
Functional Programming Principles in Scala. Martin Odersky
Functional Programming Principles in Scala Martin Odersky Programming Paradigms Paradigm: In science, a paradigm describes distinct concepts or thought patterns in some scientific discipline. Main programming
More informationAn introduction to functional programming. July 23, 2010
An introduction to functional programming July 23, 2010 About Outline About About What is functional programming? What is? Why functional programming? Why? is novel. is powerful. is fun. About A brief
More informationEECS 700 Functional Programming
EECS 700 Functional Programming Dr. Andy Gill University of Kansas February 16, 2010 1 / 41 Parsing A parser is a program that analyses a piece of text to determine its syntactic structure. The expression
More informationFusion-powered EDSLs
Fusion-powered EDSLs Philippa Cowderoy flippa@flippac.org Fusion-powered EDSLs p. Outline What is fusion? Anatomy of an EDSL Shallow vs deep embedding Examples: Identity & State monads Self-analysing EDSL
More informationPractical Haskell. An introduction to functional programming. July 21, Practical Haskell. Juan Pedro Villa-Isaza. Introduction.
Practical Practical An introduction to functional programming July 21, 2011 Contents Practical Practical is fun, and that s what it s all about! Even if seems strange to you at first, don t give up. Learning
More informationCollege Functors, Applicatives
College 2016-2017 Functors, Applicatives Wouter Swierstra with a bit of Jurriaan Hage Utrecht University Contents So far, we have seen monads define a common abstraction over many programming patterns.
More informationHaskell 101. (Version 1 (July 18, 2012)) Juan Pedro Villa Isaza
Haskell 101 (Version 1 (July 18, 2012)) Juan Pedro Villa Isaza Haskell 101: Contents Introduction Tutorial Homework Bibliography Haskell 101: Contents Introduction Tutorial Homework Bibliography Haskell
More informationCSC324 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 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 First-order vs. higher-order
More informationApplicative, traversable, foldable
Applicative, traversable, foldable Advanced functional programming - Lecture 3 Wouter Swierstra 1 Beyond the monad So far, we have seen how monads define a common abstraction over many programming patterns.
More informationCSC324 Principles of Programming Languages
CSC324 Principles of Programming Languages http://mcs.utm.utoronto.ca/~324 November 14, 2018 Today Final chapter of the course! Types and type systems Haskell s type system Types Terminology Type: set
More informationFirst Haskell Exercises
First Haskell Exercises CS110 November 23, 2016 Although it is possible to install Haskell on your computer, we want to get started quickly, so we will be using an online Haskell programming system (also
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 informationDenotational Semantics. Domain Theory
Denotational Semantics and Domain Theory 1 / 51 Outline Denotational Semantics Basic Domain Theory Introduction and history Primitive and lifted domains Sum and product domains Function domains Meaning
More informationType-Safe Observable Sharing in Haskell
Type-Safe Observable Sharing in Haskell Andy Gill The University of Kansas September 3, 2009 Andy Gill (The University of Kansas) Type-Safe Observable Sharing in Haskell September 3, 2009 1 / 27 Domain
More informationHaskell Overloading (1) LiU-FP2016: Lecture 8 Type Classes. Haskell Overloading (3) Haskell Overloading (2)
Haskell Overloading (1) LiU-FP2016: 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 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 informationMonads and all that I. Monads. John Hughes Chalmers University/Quviq AB
Monads and all that I. Monads John Hughes Chalmers University/Quviq AB Binary Trees in Haskell data Tree a = Leaf a Branch (Tree a) (Tree a) deriving (Eq,Show) Cf Coq: Inductive tree (A:Set) : Set := leaf
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 informationWayne State University Department of Computer Science CSC 5991: Advanced Web Technologies. Functional (Scala) Programming for the Web.
Wayne State University Department of Computer Science CSC 5991: Advanced Web Technologies Functional (Scala) Programming for the Web Fall 2016 A Hybrid Course or/ and Traditional: Hybrid section: CSC 5991,
More informationThese notes are intended exclusively for the personal usage of the students of CS352 at Cal Poly Pomona. Any other usage is prohibited without
These notes are intended exclusively for the personal usage of the students of CS352 at Cal Poly Pomona. Any other usage is prohibited without previous written authorization. 1 2 The simplest way to create
More informationCSCE 314 Programming Languages
CSCE 314 Programming Languages Haskell: Declaring Types and Classes Dr. Hyunyoung Lee 1 Outline Declaring Data Types Class and Instance Declarations 2 Defining New Types Three constructs for defining types:
More informationAlgebraic Types. Chapter 14 of Thompson
Algebraic Types Chapter 14 of Thompson Types so far Base types Int, Integer, Float, Bool, Char Composite types: tuples (t 1,t 2,,t n ) lists [t 1 ] functions (t 1 -> t 2 ) Algebraic types enumerated, product
More informationCSCE 314 Programming Languages Functors, Applicatives, and Monads
CSCE 314 Programming Languages Functors, Applicatives, and Monads Dr. Hyunyoung Lee 1 Motivation Generic Functions A common programming pattern can be abstracted out as a definition. For example: inc ::
More informationSemantics of programming languages
Semantics of programming languages Informatics 2A: Lecture 27 John Longley School of Informatics University of Edinburgh jrl@inf.ed.ac.uk 21 November, 2011 1 / 19 1 2 3 4 2 / 19 Semantics for programming
More informationDomain Specific Languages for Small Embedded Systems
Domain Specific Languages for Small Embedded Systems Mark Grebe Department of Electrical Engineering and Computer Science PADL 2016 The University of Kansas April 27, 2018 Small Embedded Systems Small,
More informationMonads. Bonus lecture 2017 David Sands
Monads Bonus lecture 2017 David Sands Our version of the story, so far. Monad is the class of instructions. Instructions can be built using do notation. We have seen two kinds of instructions i.e. two
More informationHaskell Introduction Lists Other Structures Data Structures. Haskell Introduction. Mark Snyder
Outline 1 2 3 4 What is Haskell? Haskell is a functional programming language. Characteristics functional non-strict ( lazy ) pure (no side effects*) strongly statically typed available compiled and interpreted
More informationLivin la via loca Coercing Types with Class
Livin la via loca Coercing Types with Class Baldur Blöndal Ryan Scott 1 Andres Löh 2 1 Indiana University 2 Well-Typed LLP rgscott@indiana.edu github.com/ryanglscott Glasgow Haskell Compiler (or, GHC)
More informationParsing. Zhenjiang Hu. May 31, June 7, June 14, All Right Reserved. National Institute of Informatics
National Institute of Informatics May 31, June 7, June 14, 2010 All Right Reserved. Outline I 1 Parser Type 2 Monad Parser Monad 3 Derived Primitives 4 5 6 Outline Parser Type 1 Parser Type 2 3 4 5 6 What
More informationEvery Animation Should Have a Beginning, a Middle, and an End
Every Animation Should Have a Beginning, a Middle, and an End A Case Study of using a Functor-based Animation Language Kevin Matlage and Andy Gill Information Technology and Telecommunication Center Department
More information10 Combining Deep and Shallow DSL Embedding
10 Combining Deep and Shallow DSL Embedding Have your cake and eat it too 1 data Cmd = Line Point Point Tri Point Int Int Circle Point Int Seq Cmd Cmd sem :: Cmd Pic sem (Line p1 p2) = Line p1 p2 sem (Circle
More informationCOSE212: Programming Languages. Lecture 3 Functional Programming in OCaml
COSE212: Programming Languages Lecture 3 Functional Programming in OCaml Hakjoo Oh 2017 Fall Hakjoo Oh COSE212 2017 Fall, Lecture 3 September 18, 2017 1 / 44 Why learn ML? Learning ML is a good way of
More informationCS 320: Concepts of Programming Languages
CS 320: Concepts of Programming Languages Wayne Snyder Computer Science Department Boston University Lecture 08: Type Classes o o Review: What is a type class? Basic Type Classes: Eq, Ord, Enum, Integral,
More informationM301: Software Systems & their Development. Unit 4: Inheritance, Composition and Polymorphism
Block 1: Introduction to Java Unit 4: Inheritance, Composition and Polymorphism Aims of the unit: Study and use the Java mechanisms that support reuse, in particular, inheritance and composition; Analyze
More informationApplicative, traversable, foldable
Applicative, traversable, foldable Advanced functional programming - Lecture 4 Wouter Swierstra and Alejandro Serrano 1 Beyond the monad So far, we have seen how monads define a common abstraction over
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 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 4-9, Thursday, September 15, 2005; remaining
More informationCSCE 314 Programming Languages
CSCE 314 Programming Languages Final Review Part I Dr. Hyunyoung Lee 1 Programming Language Characteristics Different approaches to describe computations, to instruct computing devices E.g., Imperative,
More informationCS 211 Winter 2004 Sample Final Exam (Solutions)
CS 211 Winter 2004 Sample Final Exam (Solutions) Instructor: Brian Dennis, Assistant Professor TAs: Tom Lechner, Rachel Goldsborough, Bin Lin March 16, 2004 Your Name: There are 6 problems on this exam.
More informationCOL106: Data Structures, I Semester Assignment 4 A small search engine
COL106: Data Structures, I Semester 2015-16 Assignment 4 A small search engine September 26, 2015 In this assignment we will build the basic data structure underlying search engines: an inverted index.
More informationCSCC24 Functional Programming Scheme Part 2
CSCC24 Functional Programming Scheme Part 2 Carolyn MacLeod 1 winter 2012 1 Based on slides from Anya Tafliovich, and with many thanks to Gerald Penn and Prabhakar Ragde. 1 The Spirit of Lisp-like Languages
More informationCS205: Scalable Software Systems
CS205: Scalable Software Systems Lecture 4 September 14, 2016 Lecture 4 CS205: Scalable Software Systems September 14, 2016 1 / 16 Quick Recap Things covered so far Problem solving by recursive decomposition
More informationGADTs. 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 informationMonads in Haskell. Nathanael Schilling. December 12, 2014
Monads in Haskell Nathanael Schilling December 12, 2014 Abstract In Haskell, monads provide a mechanism for mapping functions of the type a -> m b to those of the type m a -> m b. This mapping is dependent
More informationStructural 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 informationHaske k ll An introduction to Functional functional programming using Haskell Purely Lazy Example: QuickSort in Java Example: QuickSort in Haskell
Haskell An introduction to functional programming using Haskell Anders Møller amoeller@cs.au.dk The most popular purely functional, lazy programming language Functional programming language : a program
More informationFacade and Adapter. Comp-303 : Programming Techniques Lecture 19. Alexandre Denault Computer Science McGill University Winter 2004
Facade and Adapter Comp-303 : Programming Techniques Lecture 19 Alexandre Denault Computer Science McGill University Winter 2004 March 23, 2004 Lecture 19 Comp 303 : Facade and Adapter Page 1 Last lecture...
More informationHarvard School of Engineering and Applied Sciences CS 152: Programming Languages
Harvard School of Engineering and Applied Sciences CS 152: Programming Languages Lecture 18 Thursday, March 29, 2018 In abstract algebra, algebraic structures are defined by a set of elements and operations
More informationMonads. COS 441 Slides 16
Monads COS 441 Slides 16 Last time: Agenda We looked at implementation strategies for languages with errors, with printing and with storage We introduced the concept of a monad, which involves 3 things:
More informationProgramming in Haskell Aug-Nov 2015
Programming in Haskell Aug-Nov 2015 LECTURE 14 OCTOBER 1, 2015 S P SURESH CHENNAI MATHEMATICAL INSTITUTE Enumerated data types The data keyword is used to define new types data Bool = False True data Day
More informationAn introduction introduction to functional functional programming programming using usin Haskell
An introduction to functional programming using Haskell Anders Møller amoeller@cs.au.dkau Haskell The most popular p purely functional, lazy programming g language Functional programming language : a program
More informationType 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 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 informationCIS 194: Homework 5. Due Friday, October 3, Rings. No template file is provided for this homework. Download the
CIS 194: Homework 5 Due Friday, October 3, 2014 No template file is provided for this homework. Download the Ring.hs and Parser.hs files from the website, and make your HW05.hs Haskell file with your name,
More informationSoftware System Design and Implementation
Software System Design and Implementation Controlling Effects Gabriele Keller The University of New South Wales School of Computer Science and Engineering Sydney, Australia COMP3141 18s1 Examples of effects
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 informationA general introduction to Functional Programming using Haskell
A general introduction to Functional Programming using Haskell Matteo Rossi Dipartimento di Elettronica e Informazione Politecnico di Milano rossi@elet.polimi.it 1 Functional programming in a nutshell
More informationTwo approaches to writing interfaces
Two approaches to writing interfaces Interface projected from implementation: No separate interface Compiler extracts from implementation (CLU, Java class, Haskell) When code changes, must extract again
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 first-class values: Can be
More informationLinearizability Testing Manual
Linearizability Testing Manual Gavin Lowe April 8, 2016 This manual describes how to use the linearizability testing framework, described in [Low16]. The framework is available from http://www.cs.ox. ac.uk/people/gavin.lowe/linearizabiltytesting/.
More informationCS558 Programming Languages
CS558 Programming Languages Fall 2016 Lecture 6a Andrew Tolmach Portland State University 1994-2016 Functional Programming An alternative paradigm to imperative programming First-class functions Emphasis
More informationFunctional Programming. Pure Functional Languages
Functional Programming Pure functional PLs S-expressions cons, car, cdr Defining functions read-eval-print loop of Lisp interpreter Examples of recursive functions Shallow, deep Equality testing 1 Pure
More informationGetting Started with Haskell (10 points)
Massachusetts Institute of Technology Department of Electrical Engineering and Computer Science 6.827 Multithreaded Parallelism: Languages and Compilers Problem Set 1 Out: September 19, 2006 Due: October
More informationAbstract Data Types. Functional Programming and Reasoning. Dr Hans Georg Schaathun. University of Surrey. Spring 2010 Week 4
Abstract Data Types Functional Programming and Reasoning Dr Hans Georg Schaathun University of Surrey Spring 2010 Week 4 Dr Hans Georg Schaathun Abstract Data Types Spring 2010 Week 4 1 / 32 Outline 1
More informationChapter 15. Functional Programming Languages
Chapter 15 Functional Programming Languages Copyright 2009 Addison-Wesley. All rights reserved. 1-2 Chapter 15 Topics Introduction Mathematical Functions Fundamentals of Functional Programming Languages
More informationCIS 194: Homework 4. Due Wednesday, February 18, What is a Number?
CIS 194: Homework 4 Due Wednesday, February 18, 2015 What is a Number? This may sound like a deep, philosophical question, but the Haskell type system gives us a simple way to answer it. A number is any
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 informationProgramming 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 informationThe story so far. Elements of Programming Languages. Pairs in various languages. Pairs
Elements of Programming Languages Lecture 6: Data structures James Cheney University of Edinburgh October 9, 2017 The story so far We ve now covered the main ingredients of any programming language: Abstract
More informationLogical Methods in... using Haskell Getting Started
Logical Methods in... using Haskell Getting Started Jan van Eijck May 4, 2005 Abstract The purpose of this course is to teach a bit of functional programming and logic, and to connect logical reasoning
More informationEXAM Computer Science 1 Part 1
Maastricht University Faculty of Humanities and Science Department of Knowledge Engineering EXAM Computer Science 1 Part 1 Block 1.1: Computer Science 1 Code: KEN1120 Examiner: Kurt Driessens Date: Januari
More informationProgramming 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 informationCSE399: Advanced Programming. Handout 2
CSE399: Advanced Programming Handout 2 Higher-Order Programming Functions as Data In Haskell (and other functional languages), functions can be treated as ordinary data they can be passed as arguments
More informationMonads and all that III Applicative Functors. John Hughes Chalmers University/Quviq AB
Monads and all that III Applicative Functors John Hughes Chalmers University/Quviq AB Recall our expression parser expr = do a
More informationAdvanced 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 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 informationCIS 194: Homework 5. Due Monday, 18 February. Expressions. (2 + 3) 4 would be represented by the value
CIS 194: Homework 5 Due Monday, 18 February Files you should submit: Calc.hs, containing a module of the same name. As we saw in class, Haskell s type classes provide ad-hoc polymorphism, that is, the
More informationFunctional Programming. Pure Functional Languages
Functional Programming Pure functional PLs S-expressions cons, car, cdr Defining functions read-eval-print loop of Lisp interpreter Examples of recursive functions Shallow, deep Equality testing 1 Pure
More informationGADTs. 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 informationA method in creating 3D models: From shape to shape, from shapes to model (October 2016)
A method in creating 3D models: From shape to shape, from shapes to model (October 2016) M. Sinan Serbetcioglu, BS* Abstract In this paper, we try to create 3D models by using some geometrical primitives.
More informationTypes and Static Type Checking (Introducing Micro-Haskell)
Types and Static (Introducing Micro-Haskell) Informatics 2A: Lecture 14 John Longley School of Informatics University of Edinburgh jrl@inf.ed.ac.uk 17 October 2017 1 / 21 1 Types 2 3 4 2 / 21 So far in
More informationCS 381: Programming Language Fundamentals
CS 381: Programming Language Fundamentals Summer 2017 Semantics July 12, 2017 Outline What is semantics? Semantics of naming 2 Why do we need semantics? Understand what program constructs do Judge the
More informationAdvanced 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 informationSolution sheet 1. Introduction. Exercise 1 - Types of values. Exercise 2 - Constructors
Solution sheet 1 Introduction Please note that there can be other solutions than those listed in this document. This is a literate Haskell file which is available as PDF, as well as literate Haskell source
More informationThis is a talk given by me to the Northwest C++ Users Group on May 19, 2010.
This is a talk given by me to the Northwest C++ Users Group on May 19, 2010. 1 I like this picture because it clearly shows what is private and what is shared. In the message-passing system, threads operate
More informationRound-Tripping Balls. Building A Bi-Directional Printer/Parser
Round-Tripping Balls Building A Bi-Directional Printer/Parser 1 / 46 Introducing: Enterprise JSON 2 / 46 Introducing: Enterprise JSON datetime "27/6/2013 10:29 pm" 2 / 46 Introducing: Enterprise JSON datetime
More informationGADTs. 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 informationBibliography. Analyse et Conception Formelle. Lesson 5. Crash Course on Scala. Scala in a nutshell. Outline
Bibliography Analyse et Conception Formelle Lesson 5 Crash Course on Scala Simply Scala. Onlinetutorial: http://www.simply.com/fr http://www.simply.com/ Programming in Scala, M. Odersky, L. Spoon, B. Venners.
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 informationNotes from a Short Introductory Lecture on Scala (Based on Programming in Scala, 2nd Ed.)
Notes from a Short Introductory Lecture on Scala (Based on Programming in Scala, 2nd Ed.) David Haraburda January 30, 2013 1 Introduction Scala is a multi-paradigm language that runs on the JVM (is totally
More informationCS558 Programming Languages
CS558 Programming Languages Fall 2016 Lecture 7a Andrew Tolmach Portland State University 1994-2016 Values and Types We divide the universe of values according to types A type is a set of values and a
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 informationCPSC 427: Object-Oriented Programming
CPSC 427: Object-Oriented Programming Michael J. Fischer Lecture 12 October 10, 2016 CPSC 427, Lecture 12 1/27 Uses of Pointers Custody of Objects Move Semantics CPSC 427, Lecture 12 2/27 Uses of Pointers
More informationPart 1. An Implementation of the Gale-Shapley Algorithm
Part 1 An Implementation of the Gale-Shapley Algorithm CSCI 3110 Code Fall 2015 1 Introduction Here s the pseudo-code of the Gale-Shapley algorithm from class: GALESHAPLEY(M, W ) while there is an unmarried
More informationObject-Based Programming. Programming with Objects
ITEC1620 Object-Based Programming g Lecture 8 Programming with Objects Review Sequence, Branching, Looping Primitive datatypes Mathematical operations Four-function calculator Scientific calculator Don
More informationCOSC-589 Web Search and Sense-making Information Retrieval In the Big Data Era. Spring Instructor: Grace Hui Yang
COSC-589 Web Search and Sense-making Information Retrieval In the Big Data Era Spring 2016 Instructor: Grace Hui Yang The Web provides abundant information which allows us to live more conveniently and
More informationProgramming Languages and Techniques (CIS120)
Programming Languages and Techniques () Lecture 20 February 28, 2018 Transition to Java Announcements HW05: GUI programming Due: THURSDAY!! at 11:59:59pm Lots of TA office hours today Thursday See Piazza
More informationCOL106: Data Structures, I Semester Assignment 3-4 A small search engine
COL106: Data Structures, I Semester 2018-19 Assignment 3-4 A small search engine September 24, 2018 In this assignment we will build the basic data structure underlying search engines: an inverted index.
More informationCSE115 / CSE503 Introduction to Computer Science I. Dr. Carl Alphonce 343 Davis Hall Office hours:
CSE115 / CSE503 Introduction to Computer Science I Dr. Carl Alphonce 343 Davis Hall alphonce@buffalo.edu Office hours: Thursday 12:00 PM 2:00 PM Friday 8:30 AM 10:30 AM OR request appointment via e-mail
More information