Skip main navigation

New offer! Get 30% off your first 2 months of Unlimited Monthly. Start your subscription for just £29.99 £19.99. New subscribers only. T&Cs apply

Find out more

Why I/O?

While visiting the National Museum of Computing, Dr Jeremy Singer takes time to explain about input and output in computer systems.
8
JEREMY: How do computer programs interact with the outside world?
15.3
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.
71.4
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.
101.1
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.

This article is from the free online

Functional Programming in Haskell: Supercharge Your Coding

Created by
FutureLearn - Learning For Life

Reach your personal and professional goals

Unlock access to hundreds of expert online courses and degrees from top universities and educators to gain accredited qualifications and professional CV-building certificates.

Join over 18 million learners to launch, switch or build upon your career, all at your own pace, across a wide range of topic areas.

Start Learning now