O'Reilly logo

Get Programming with Haskell by Will Kurt

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required