Input/Output
This chapter explains Haskell’s unique way of communicating with the outside world. The outside world is defined as any entities outside of the Haskell program, such as the user, the filesystem, the network, and the operating system. It’s used to display text to a user and get their input, read and write files, access and provide web services, get the current time and date, and so on.
The reason Haskell has a unique approach is twofold:
- Firstly, lazy evaluation makes working with plain functions for communication purposes impossible from a practical point of view. The order of execution is too unpredictable to have a sensible interaction with a third party.
- Secondly, a strong principle of the Haskell language is that its functions resemble as closely as possible the mathematical definition of what a function is. For one, this means that functions should be predictable in a very precise sense – for the same input, a function should always...