Page 1

Programming IO

Keeping pure and impure functions apart

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

More IO in Haskell

Page 10

IO and purity in Haskell

Page 11

Using IO results in GHCi

Page 12

The do notation

Page 13

Testing it

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

Page 14

Doing IO and returning results

Page 15

The difference

Page 16

Why pure functions?

Purity is good for modularity and simplifies debugging and testing.

Page 17

More examples 1

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

More examples 2

Page 19

More examples 3

Page 20

A larger example