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

Page 7
Curried functions

Uncurried vs curried functions as tables

Page 8

Live Demo

Page 9

Case study: sums and products of lists

Page 10

Factoring out the differences

Page 11

Code reuse

Page 12

An intuition about foldr

Page 13

Quiz

What does these function do?

Page 14

Passing functions as arguments

Page 15

Partial application

Page 16

Partial application of infix operators

Page 17

Function composition

Page 18

Anonymous functions

Page 19

Example

Page 20

Eta conversion

Page 21

Eta conversion examples

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

removeSpaces = filter (not . isSpace)

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

More standard higher-order functions

Page 23

Lines

Page 24

Words

Page 25

A bigger example: word counting

Page 26

Lessons

Page 27

Higher order functions in other languages?