Contact FutureLearn for Support
Skip main navigation
We use cookies to give you a better experience, if that’s ok you can close this message and carry on browsing. For more info read our cookies policy.
We use cookies to give you a better experience. Carry on browsing if you're happy with this, or read our cookies policy for more information.

Skip to 0 minutes and 8 secondsJEREMY: How do computer programs interact with the outside world?

Skip to 0 minutes and 15 secondsUsing 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 secondsNumber 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 secondsI'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.

Why I/O?

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.

Share this video:

This video is from the free online course:

Functional Programming in Haskell: Supercharge Your Coding

University of Glasgow

Course highlights Get a taste of this course before you join:

  • Haskell history poster
    Brief History of Haskell
    article

    What are the origins of the Haskell programming language? In this article, Dr Jeremy Singer explores the history of Haskell.