Input, Output, and Concatenation with Haskell

Advertisement

Advertisement

Standard in and Standard out (STDIN/STDOUT) are very common methods of interacting with the user. Standard in is typically the keyboard and standard out is the terminal. Haskell makes this very easy to access. The getLine function gets a value from the user and putStrLn and putStr allow you to write to output. The ++ operator is used to concatenate strings.

main = do
     putStrLn "What is your name?"
     username <- getLine
     putStrLn $ "Hello, " ++ username ++ "!"

Advertisement

Advertisement