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.
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.