chapter three

3 Line by line

 

This chapter covers

  • Facilitating side effects and input/output within Haskell
  • Using side-effect free, pure code within impure code
  • Interacting with the operating systems environment
  • Using partial function application to write more concise code
  • Modeling program behavior with types
  • Incorporating a simple for of command line argument parsing into our programs

In the previous chapter we learned how to construct algorithms to transform strings and explored the basics of programming in Haskell. However, we were only able to test our functionality in GHCi. Now, we want to turn our attention to writing our first real program, which can be invoked from the command line.

When working on the command line or writing automated scripts on UNIX-like systems often pipelines of multiple programs are used for achieving certain tasks like searching or transforming data. For facilitating inter-process communication easily, streams of texts are used to pass messages from one process to another. This is usually done with the pipe symbol |. This idea is illustrated by figure 3.1.

Figure 3.1. An example of how to transform data using pipes with shell commands
placeholder shellpipe

For this to work many tools exist in the UNIX space that perform basic tasks which, when combined in a pipeline, perform a bigger action. A good example for a collection of such tools are the GNU core utilities which are bundled with almost every Linux distribution in use today.

3.1 Talking to the Outside

3.1.1 Call to Action

3.2 With Purity Inside

3.2.1 Let It Be

3.3 Hello to the Environment

3.3.1 Call Me Maybe

3.3.2 To Parse Or Not To Parse

3.4 Every line counts

3.4.1 Number, Number On The Line

3.4.2 Hold The Line

3.5 To Pad Things Out

3.5.1 Pretty Printing Of Numerous Numbers

3.6 Another Kind Of Map