-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathIOExercise.hs
46 lines (38 loc) · 871 Bytes
/
IOExercise.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
{-
---
fulltitle: "In class exercise: IOExercise"
date:
---
In-class exercise (IO Monad)
-}
module IOExercise where
import System.FilePath
{-
Rewrite these programs so that they do not use 'do'.
(Make sure that you do not change their behavior!)
-}
simpleProgram :: IO ()
simpleProgram = do
putStrLn "This is a simple program that does IO."
putStrLn "What is your name?"
inpStr <- getLine
putStrLn ("Welcome to Haskell, " ++ inpStr ++ "!")
lengthProgram :: IO Int
lengthProgram = do
let x = length [1, 2, 3, 4, 5, 6]
putStrLn ("The length of the list is" ++ show x)
return x
{-
>
-}
anotherProgram :: IO ()
anotherProgram = do
putStrLn "What is your name?"
inpStr <- getLine
if inpStr == "Haskell"
then do
putStrLn "You rock!"
return ()
putStrLn "Really!!"
else putStrLn ("Hello " ++ inpStr)
putStrLn "That's all!"