-
Notifications
You must be signed in to change notification settings - Fork 5
Notes for Week 9 Input and Output
- Write a program which asks the user for the base and height of a right angled triangle, calculates its area and prints it to the screen. The interaction should look something like:
The base? 3.3 The height? 5.4 The area of that triangle is 8.91
Hint: you can use the function read to convert user strings like "3.3" into numbers like 3.3 and function show to convert a number into string.
- Write a program that asks the user for his or her name. If the name is one of Simon, John or Phil, tell the user that you think Haskell is a great programming language. If the name is Koen, tell them that you think debugging Haskell is fun. Otherwise, tell the user that you don't know who he or she is.
Write two different versions of this program, one using if statements, the other using a case statement.
- Consider two versions of the same program:
a) do name <- getLine let loudName = makeLoud name putStrLn ("Hello " ++ loudName ++ "!") putStrLn ("Oh boy! Am I excited to meet you, " ++ loudName)
b) do name <- getLine let loudName = makeLoud name in do putStrLn ("Hello " ++ loudName ++ "!") putStrLn ("Oh boy! Am I excited to meet you, " ++ loudName)
Why does version b of the let binding require an extra do keyword? Do you always need the extra do?
Is Haskell statically linked?
Yes. To dynamically link do this
ghc --make -dynamic Main.hs
More info here http://www.haskell.org/ghc/docs/6.12.1/html/users_guide/using-shared-libs.html
//TODO
Then operator (>>) "operator is easy to translate between do notation and plain code"
putStr "Hello" >> putStr " " >> putStr "world!" >> putStr "\n"
We can rewrite it in do notation as follows:
do putStr "Hello" putStr " " putStr "world!" putStr "\n"