chapter9 - 1 PROGRAMMING IN HASKELL Chapter 9 Interactive...

Info iconThis preview shows pages 1–8. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: 1 PROGRAMMING IN HASKELL Chapter 9 - Interactive Programs 2 Introduction To date, we have seen how Haskell can be used to write batch programs that take all their inputs at the start and give all their outputs at the end. batch program inputs outputs 3 However, we would also like to use Haskell to write interactive programs that read from the keyboard and write to the screen, as they are running. interactive program inputs outputs keyboard screen 4 The Problem Haskell programs are pure mathematical functions: However, reading from the keyboard and writing to the screen are side effects: ❚ Haskell programs have no side effects . ❚ Interactive programs have side effects . 5 The Solution Interactive programs can be written in Haskell by using types to distinguish pure expressions from impure actions that may involve side effects. IO a The type of actions that return a value of type a. 6 For example: IO Char IO () The type of actions that return a character. The type of purely side effecting actions that return no result value. ❚ () is the type of tuples with no components. Note: 7 Basic Actions The standard library provides a number of actions, including the following three primitives: getChar :: IO Char ❚ The action getChar reads a character from the keyboard, echoes it to the screen, and returns the character as its result value: 8...
View Full Document

This note was uploaded on 06/11/2011 for the course CSCE 330 taught by Professor Valtorta during the Spring '10 term at Columbia SC.

Page1 / 21

chapter9 - 1 PROGRAMMING IN HASKELL Chapter 9 Interactive...

This preview shows document pages 1 - 8. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online