Viewing the Contents of an ASCII or UTF8 Encoded Text File

Now that you have a basic application up and running, it’s time to make it do something useful. We’ll add several features to our program throughout this chapter, but for now let’s focus on a single feature: displaying the contents of a file to the screen. To do that we’ll need to:

  1. Know which file the user wants to view
  2. Read the contents of the file
  3. Write the contents of the file to the screen

We’ll take each of these requirements in order. Once we’re done you’ll have a program that works like a minimal version of the Unix cat command.

Reading a Filename from the Command Line

Before we can do anything with a file, like reading it, we need to know what file we’re working with. For a command ...

Get Effective Haskell now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.