2019-09-18 19:31
Page 1

Programming IO

How to avoid harmful side effects

Page 2

Remember the word counting function from last week?

Page 3

Standalone Haskell programs

Page 4

Creating IO actions

Page 5

The program countWords

Page 6

Pure functions

In Haskell, functions are pure

Page 7

Equal and interchangeable

Page 8

An example in Python

Page 9

An example in JavaScript

Page 10

More IO in Haskell

Page 11

IO and purity in Haskell

Page 12

Using IO results in GHCi

Page 13

The do notation

Page 14

Testing it

showTheDifference Enter two numbers: 15  12  The difference is: 3

Page 15

Doing IO and returning results

Page 16

The difference

Page 17

Why pure functions?

Purity is good for modularity and simplifies debugging and testing.

Page 18

More examples 1

copyFile :: FilePath -> FilePath -> IO ()
copyFile from to = do s <- readFile from
                      writeFile to s
Page 19

More examples 2

Page 20

More examples 3

Page 21

A larger example

Hangman