Page 1

Laziness

Laziness is just a different kind of productivity

Page 2

Bob Harper visiting Chalmers 1

Page 3

Bob Harper visiting Chalmers 2

Page 4

Haskell is a purely functional language

In Haskell, functions are pure

Page 5

Lazy — Eager — Parallel

Page 6

Concurrency vs Parallelism

Page 7

Haskell is pure and lazy

What does this mean?

Page 8

Parallel computation in Haskell

Page 9

Lazy or eager, what's the difference?

Page 10

All languages have some laziness

Page 11

Examples of laziness

Live demo

Page 12

Familiar example: lazy boolean operators

Page 13

Observing laziness in GHCi

Two useful commands

Page 14

Infinite lists

Examples

ones = 1 : ones

numbers = [1..]
  
-- count n = [n..]
countUp n = n:countUp (n+1)

-- fromTo start stop == [start .. stop]
fromTo start stop = take (stop-start+1) (countUp start)

-- Fibonacci numbers
fibs = 1 : 1 : zipWith (+) fibs (tail fibs)
Page 15

Example: primes numbers

Page 16

Predefined functions that create infinite lists

Page 17

More examples

Examples where laziness improves reusability

Page 18

Newton's method

Page 19

Properties of zip

Page 20

prop_zip_length problem

Page 21

The length of infinite lists

Page 22

Lazy natural numbers

Page 23

A new length function

Page 24

prop_zip_length problem solved

Page 25

Search Example

Exercise

Page 26

Tree equality

Page 27

Fringe equality

Page 28

Lazy IO