2018-11-18 21:50
Page 1

Higher order functions

The Heart and Soul of Functional Programming

Page 2

Announcement

Drop-in office hours

Page 3

What is a higher order function?

Page 4

The types of higher order functions

Page 5

Is this a big deal?

Page 6

Live Demo

Page 7

Passing functions as arguments

Page 8

Partial application

Page 9

Partial application of infix operators

Page 10

Function composition

Page 11

Anonymous functions

Page 12

Functions returning functions?

Page 13
Functions returning functions?
Page 14

Curried functions

Page 15
Curried functions

Uncurried vs curried functions as tables

Page 16

Defining higher order functions

First examples

Page 17

Case study: sums and products of lists

Page 18

Factoring out the differences

Page 19

Code reuse

Page 20

An intuition about foldr

Page 21

Quiz

What does these function do?

Page 22

Example

Page 23

Eta conversion

Page 24

Eta conversion examples

or     = foldr (||) False
and    = foldr (&&) True
concat = foldr (++) []

removeSpaces = filter (not . isSpace)

unlines = foldr (\xs ys->xs++"\n"++ys) []
Page 25

More standard higher-order functions

Page 26

Lines

Page 27

Words

Page 28

A bigger example: word counting

Page 29

Lessons

Page 30

Higher order functions in other languages?

Page 31

Extra

Quiz

How many arguments do the following functions have?