Skip to 0 minutes and 8 seconds JEREMY: How do computer programs interact with the outside world?
Skip to 0 minutes and 15 seconds Using input and output. In this dissected PC hardware here, we see the input might arrive when the user presses keys on the keyboard or wiggles the mouse or, perhaps, when the file is read into memory from the disk. Outputs are visible to the external surroundings of the PC when the program writes data to the graphics card to be displayed on the screen or, perhaps, where a file is written back to disk. Haskell programs use something called the IO monad to interact with input/output. We’ll go into more detail about I/O and monads later on in the course. But for now, we just need to know two things.
Skip to 1 minute and 11 seconds Number one, when a function is using input or output, its type must contain IO. And number two, the IO monad ensures that input/output operations occur in a fixed sequence. For example, we must check the red button is pressed before we launch the missiles.
Skip to 1 minute and 41 seconds I’m going to invite you to look at the next interactive tutorial, now, which covers I/O in Haskell. Our I/O operations are much more mundane than launching missiles. We’ll just be writing strings to the console using putStrLn and reading character input from the standard terminal using getLine. As you do the tutorial, watch out and see where the IO type pops up. Thanks.
Computers interact with the outside world via input and output (I/O). The Haskell programming language has specific support for I/O operations, which we will explore in the next few steps.
© University of Glasgow