0

I am taking input from the user and the code is as follows:

putStrLn $ "Enter number"
num <- getLine
main = print $ num

When I run this code, the compiler gives following error:

ra.hs:10:5: parse error on input `<-'

How can I remove this error? I have tried to use spaces, as well as tab characters, but the error persists. Please help.

1

2 Answers 2

5

You have to move all of your code into main

main = do
    putStrLn "Enter number"
    num <- getLine
    print num

The area outside of main is for declarations, etc. You use <- inside of a do.

Also, you don't need the extra $'s when there is a single parameter.

Sign up to request clarification or add additional context in comments.

Comments

0

It just works for me, if I put lines to inside main.

main:: IO ()
main = do
    putStrLn $ "Enter number"
    num <- getLine
    print $ num

Here is runnable code: https://paiza.io/projects/CCc2kEbxXWfRRdVYAqbXww

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.