0
defaultFileName :: [Char]
defaultFileName = "Test.log"

defaultSearchName :: String
defaultSearchName = "xyz"

This code can be compiled:

a3 :: Int -> [[Char]] -> IO [Char]
a3 index arg = 
  if null arg
    then do
      a <- putStrLn "No parameters have been passed."
      a <- putStrLn $ "1 Default search string: " ++ defaultSearchName
      a <- putStrLn ("2 Default file name: " ++ defaultFileName)
      return defaultFileName
    else return (arg!!index)

once I add an extra IF-THEN-ELSE, I cannot compile it anymore

a3 :: Int -> [[Char]] -> IO [Char]
a3 index arg = 
  if null arg
    then do
      a <- putStrLn "No parameters have been passed."
      a <- putStrLn $ "1 Default search string: " ++ defaultSearchName
      a <- putStrLn ("2 Default file name: " ++ defaultFileName)
      if index == 0
        then  return defaultSearchName
        else return defaultFileName
    else return (arg!!index)

why???? It is so frustrating with every single step.

Random Dev
  • 51,810
  • 9
  • 92
  • 119
  • I forgotten to put the compile error, which is: parse error on input `if' – user1863063 Jan 28 '16 at 11:49
  • 2
    The error is right there under you inserted `if` - it's a **fat** ugly tab right there (note: you will see this if you edit your answer here - SO will reformat the markdown and remove the tab in this view) – Random Dev Jan 28 '16 at 12:13

1 Answers1

5

Your code compiles fine. Are you sure you don't have tabs and spaces interleaved there as an indentation?

Try ghci -fwarn-tabs yourfile.hs

phadej
  • 11,947
  • 41
  • 78
  • 1
    Wouldn't this be more appropriate as a comment? – jub0bs Jan 28 '16 at 12:06
  • @Jubobs kind of, but it's overwhelmingly likely that tabs are indeed the culprit. – leftaroundabout Jan 28 '16 at 12:13
  • 1
    Indeed, there are tabs in the pasted code (we need to press "edit" to see them). – chi Jan 28 '16 at 12:14
  • @Carsten Sometimes I wish `-Wall` were the default. Even the perl man page lists "-w is not the default" in the BUGS section, IIRC ;-) – chi Jan 28 '16 at 12:17
  • @Carsten: GHC-7.10 _does_ warn about tabs by default, so we shouldn't have this problem for too long anymore. – leftaroundabout Jan 28 '16 at 13:19
  • @leftaroundabout really? **great** - never noticed (well my editor helps me out of that mess) so thank you for letting me know (feeling like an ass now... have to delete some comments) – Random Dev Jan 28 '16 at 13:23
  • Thank you all for your help.Indeed this was related to tabs (which I thought I double checked - clearly not good enough) – user1863063 Jan 28 '16 at 14:35
  • @user1863063 If phadej solved your problem, please consider accepting his answer. – jub0bs Jan 29 '16 at 15:38