Page 1

Higher order functions

The Heart and Soul of Functional Programming

Page 2

What is a higher order function?

Page 3

The types of higher order functions

Page 4

Is this a big deal?

Page 5

Functions returning functions?

Page 6

Curried functions

Compare these types:

Page 7

Live Demo

Page 8

Case study: sums and products of lists

Page 9

Factoring out the differences

Page 10

Code reuse

Page 11

An intuition about foldr

Page 12

Quiz

What does these function do?

Page 13

Passing functions as arguments

Page 14

Partial application

Page 15

Partial application of infix operators

Page 16

Function composition

Page 17

Anonymous functions

Page 18

Example

Page 19

Eta conversion

Page 20

Eta conversion examples

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

removeSpaces = filter (not . isSpace)

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

More standard higher-order functions

Page 22

Lines

Page 23

Words

Page 24

A bigger example: word counting

Page 25

Lessons

Page 26

Higher order functions in other languages?