2019-10-01 13:08
Page 1

Higher order functions 2

The Heart and Soul of Functional Programming

Page 2

Reminder

What is a higher order function?

Page 3
Reminder

Passing arguments to higher-order functions

Page 4

The types of higher order functions

Page 5

Defining map and filter

Page 6

An intuition about foldr

Page 7
An intuition about foldr
Page 8

Type type of foldr

Page 9

Quiz

What do these functions do?

Page 10

Live Demo

Page 11

More standard higher-order functions

Page 12

Lines

Page 13

Words

Page 14

zipWith

Page 15

Scalar product

Page 16

More zipWith

Page 17

Even more zipWith

Page 18

Function composition

Page 19
Function composition

Composing many functions

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) []

f = f1 . f2 . f3 . f4 . f5
Page 22

Exercise

Page 23

Functions returning functions?

Page 24
Functions returning functions?
Page 25

Curried functions

Page 26
Curried functions

Uncurried vs curried functions as tables

Page 27

Curry and uncurry

Page 28

Extra

Higher order functions in other languages?

Page 29
Extra

From the lambda (λ) calculus

Page 30
Extra

Quiz

How many arguments do the following functions have?