Say we have a short haskell program:
main = do putStr "2 + 2 = "
x <- readLn
if x == 4
then putStrLn "Correct"
else putStrLn "Wrong"
What result does he produce?
4
2 + 2 = Correct
Now, let's do it again:
main = do putStrLn "2 + 2 = "
x <- readLn
if x == 4
then putStrLn "Correct"
else putStrLn "Wrong"
It creates
2 + 2 =
4
Right
If bold 4 is entered by the user.
Can someone familiar with Haskell explain to me why this is so? And how do I get the desired result, which
2 + 2 = 4
Right
source
share