Lesson 21. Hello World!—introducing IO types

After reading lesson 21, you’ll be able to

  • Understand how Haskell handles I/O by using IO types
  • Use do-notation to perform I/O
  • Write pure programs that interact with the real world

In lesson 1, you saw a basic example of a Hello World program. In this lesson, you’ll revisit a similar program to get a better sense of how I/O works in Haskell. Here’s an example program using I/O that reads a name from the command line and prints out "Hello <name>!".

Listing 21.1. A simple Hello World program
helloPerson :: String -> String helloPerson name = "Hello" ++ " " ++ name ++ "!" main :: IO () main = do putStrLn "Hello! What's your name?" name <- getLine let statement = helloPerson name putStrLn statement ...

Get Get Programming with Haskell now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.