I've looked at questions regarding indentation, which were of no help. My indentation also looks correct but according to the compiler it isnt. What is the correct indentation and what are the rules?
readFile filename = do
inputFile <- openFile filename ReadMode
readLines inputFile
hClose inputFile
readLines inputFile =
do endof <- hIsEOF inputFile
| endof = return()
| otherwise = do
inpStr <- hGetLine inputFile
print inpStr
readLines inputFile
Using all spaces and no tabs. Error: "parse error on input '|' | endof = return() "
You could restructure your code for this, like
The guards,
| ..., belong to function definitions or case expressions. They can't appear indoblock by themselves.g =<< hIsEOF inputFileis a shorter way to writeBut a simpler option is just to use
if ... then ... else ...in thedoblock in the first place:Yet another is using LambdaCase to inline the
gdefinition:And case clauses can have guards (though here we didn't need them).