0

Why is the following code not correct ? i get this error: Last generator in do {...} must be an expression?

main = do   putStrLn "What is 2 + 2?"
            x <- readLn
            if x == 4
              then putStrLn "You're right!"
              else putStrLn "You're wrong!"
McBear Holden
  • 5,741
  • 7
  • 33
  • 55
  • This is freaking crazy ! When i copy the code i wrote in my question and paste it back it works ! But it's exactly the same ! – McBear Holden Nov 25 '11 at 20:07

2 Answers2

9

You are mixing tabs and spaces: the second and fifth line contain tabs, while the third and fourth don't.

The Haskell compiler probably expands tabs to a different number of spaces than your editor and what looks correctly indented in the editor looks messed up to the compiler.

Best avoid mixing tabs and spaces and only use one of them for indentation.

sth
  • 222,467
  • 53
  • 283
  • 367
2

You had tabulations instead of spaces. After you have pasted the code into stackoverflow there are only spaces and everything is working.

Alexander Gorshenev
  • 2,769
  • 18
  • 33