user2240649
user2240649

Reputation: 89

Haskell Input Output

Is it possible using's Haskell's input and output to be able to capture and store user entered data into variables?

For example if user was asked a question:

Enter your firstname: Ben, then firstname = Ben, Enter your surname: Davies, then surname = Davies

And finally a print statement to concatenate the 2 variables ie. firstname ++ surname = Ben Davies?

Thanks in advance for the help!

Upvotes: 0

Views: 286

Answers (2)

DiegoNolan
DiegoNolan

Reputation: 3766

Yes, it is possible.

main = do
   putStrLn "Enter your first name"
   firstName <- getLine
   putStrLn "Enter your last name"
   lastName <- getLine
   putStrLn $ "Your full name is " ++ firstName ++ " " ++ lastName

Upvotes: 4

mhwombat
mhwombat

Reputation: 8136

Yes, it's easy to do that. See this example

Upvotes: 1

Related Questions