Next week, on Friday, March 14 (Friday Piday!), I’d like to discuss the next two chapters:
Chapter 9: More Input and More Output
Chapter 10: Functionally Solving Problems
Chapter 9 builds on some of the I/O concepts we’ve learned so far, and chapter 10 has some general exercises on how to solve problems using functional programming instead of imperative programming.
After this next section, we start getting into the really exciting stuff: Applicatives, Monoids, and Monads!
Random numbers: random, randomR, mkStdGen, getStdGen
Bytestrings
We mentioned that we’ll learn better ways of handling random numbers later with the State monad. We’ll also learn how to use I/O better. I gave the following example:
-- Here's an example from the book:
main = do
withFile "girlfriend.txt" ReadMode (\handle -> do
contents <- hGetContents handle
putStr contents)
-- You can also write it like this:
main = withFile "girlfriend.txt" ReadMode $ putStr <=< hGetContents