-1

Can anyone please help me to trouble shoot this error

import System.Environment
import System.IO
import System.Directory

main = do
         (fileName:_) <- getArgs
         fileExists <- doesFileExists fileName
         if fileExists 
             then do contents <- readFile fileName
                     putStrLn $ "The file has " ++ show (length (lines contents)) ++ " lines."
             else do putStrLn "File does not exist"

I get a

doesFileExistsException.hs:12:22: error:
parse error on input `putStrLn'

error message. I made sure that there are no tabs in the file. Please let me know what is causing this error.

THanks

Srinivas
  • 2,010
  • 7
  • 26
  • 51
  • Are you sure you've posted the whole code? There's no line 12 in the piece you've shown. Also, it compiles fine for me. – Michail Mar 11 '17 at 16:31
  • Thanks for looking. This is the whole code. My standard practice is always write the file name as a comment in the first line. Maybe I might have missed a space or something. I will check. – Srinivas Mar 11 '17 at 16:46
  • In the Markdown for this post (click [edit]) there is a tab in the line with `then`. I suggest you duble-check whether it was there in your original file. – duplode Mar 11 '17 at 16:53
  • Thanks for the catch. You were right. I removed the tab and it works fine. I find Notepad ++ irritating that it inserts tabs in the code. May I ask, what editors you use for Haskell programs? – Srinivas Mar 11 '17 at 16:57
  • According to [this Q&A](http://stackoverflow.com/q/8197812/2751851), you can configure Notepad++ so that it doesn't insert tabs any more. (To answer your question: I have used Vim for a long while, though now I'm leaning towards Emacs -- so that I can use [Intero](https://commercialhaskell.github.io/intero/) -- with Evil and evil-god-state -- so that it outwardly feels like Vim.) – duplode Mar 11 '17 at 17:09
  • I think you will find anything from sublime, atom.io, vim, emacs being used in the community (ocasionally intellij + plugin, and eclipse, leksah), but most use either vim or emacs I think – epsilonhalbe Mar 11 '17 at 17:58
  • Possible duplicate of https://stackoverflow.com/questions/35855170/why-shouldnt-i-mix-tabs-and-spaces – Zeta Mar 11 '17 at 18:41

1 Answers1

0

The markdown shows that you have a tab in the then line instead of spaces, and spaces elsewhere. This will cause a parsing error in Haskell. This question has more information on the topic.

Community
  • 1
  • 1
qfwfq
  • 2,416
  • 1
  • 17
  • 30