0
votes

I am not understanding why this code is not outputting. I keep getting errors that say: parse error (possibly incorrect indentation or mismatched brackets) putStrLn "Enter how many numbers:"

 main = do
    putStrLn "Enter how many numbers:" -- clearer
    listlen <- getLine 
    if (listlen < 100)
    then 
    putStrLn "Enter a number: "
    numberString <- getLine
    let numberInt =(read numberString :: Int)
    print (numberInt)
    else 
        putStrLn " Error: listlen must be less than 100"
2
What is the line number for which you get the error? - Libby
it says. test3.hs:4:23 error: - MadeleineG

2 Answers

1
votes

When I pasted your example into my editor, the line that failed was the one after "then". If you add a "do" after "then", that error goes away.

So:

then do
putStrLn "Enter a number: "

...etc.

1
votes

The listlen is String type that cannot compare to 100. It need use read to convert it to number:

if (read listlen < 100)
...