{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

chapter9 - PROGRAMMING IN HASKELL 1 Introduction Todate,...

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

View Full Document Right Arrow Icon
1 PROGRAMMING IN HASKELL Chapter 9 - Interactive Programs
Background image of page 1

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

View Full Document Right Arrow Icon
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
Background image of page 2
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
Background image of page 3

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

View Full Document Right Arrow Icon
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 .
Background image of page 4
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.
Background image of page 5

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

View Full Document Right Arrow Icon
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:
Background image of page 6
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:
Background image of page 7

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

View Full Document Right Arrow Icon
Image of page 8
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}