Thinking About IO Types
-
Write a function that returns a value of type IO (IO String) . What happens if you try to use >>= with that? What if you want to print the string?
-
Using your function from the previous example, create a function that has the type signature: IO (IO a) -> IO a .
-
Write a function that returns a value of type [IO a] , and a second function with the type [IO a] -> IO [a] . When might you use a function like that?
Building a Command Line Calculator
-
Write a program that reads in numbers from the command line and prints the sum of the provided values.
-
Modify your previous program so that the first argument is an operation (+, -, or *) and performs the supplied operation on the list of numbers.
Building a Word Replacement Utility
Write an application that will accept three arguments on the command line:
- path : The path to a file
- needle : A word to find in the input file
- replacement : A word to use as a replacement when printing the file
When a user runs your program, you should print out the contents of the file at path , but replace all occurrences of needle with replacement in the output. To make things easier, assume that you can use the words function and don’t need to worry about handling multiple spaces or words that span lines.
Footnotes
[12]
https://www.haskell.org/onlinereport/index98.html
Copyright © 2023, The Pragmatic Bookshelf.