Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Haskell: parse error on input 'putStrLn'

I just wrote my first Haskell program, but there is an error that I cannot understand. I think it is right because I just wrote it like the example from a book. Could anyone help me please?

main = do
    putStrLn "Hello, what's your name?"
    name <- getLine
    putStrLn ("Hey" ++ name ++ ", nice to meet you!")

The error message is:

parse error on input 'putStrLn'

It is strange.

like image 258
Mel Avatar asked Jun 02 '13 05:06

Mel


1 Answers

Though it's impossible to tell from your posted code because SO converts tabs to spaces at least some of the time, the problem is likely that you input a literal tab character before putStrLn instead of four spaces as you did for the other two lines in your do block, or vice versa.

All of the statements in a do block must start with the exact same whitespace, and not just appear to line up visually. If you're using a text editor that can display literal tabs in a special way, set it up to do so; it will save you some headaches.

like image 108
Cairnarvon Avatar answered Sep 30 '22 11:09

Cairnarvon