Haskell格式化I / O错误

时间:2014-03-14 02:08:48

标签: haskell input formatting output

我在查找编译代码时出现解析错误的原因时遇到了问题。我尝试使用制表符和空格缩进但没有成功。也许我只需要另外一些关于代码的眼睛,任何帮助将不胜感激!

错误似乎来自这条线:

  

putStrLn“\ n选择选项:”

main :: IO()
main = do contents <- readFile "films.txt";
          let database = (read contents :: [Film])
          putStrLn "Please enter your name:";
          name <- getLine;
          putStrLn ("Hello " ++ name ++ "!");
          menu database
          where menu newDb = do putStrLn "\nWhat would you like to do?";
                                putStrLn "1 -> Add a film";
                                putStrLn "2 -> Display all films";
                                putStrLn "3 -> Display all films by director's name";
                                putStrLn "4 -> Display the films of an average website rating";
                                putStrLn "5 -> Display the average rating of the films of a particular actor";
                                putStrLn "6 -> Show the films you have rated, with the rating";
                                putStrLn "7 -> Rate or ReRate a film";
                                putStrLn "8 -> Display films released during or after a year, sorted in descending order of rating";
                                putStrLn "9 -> Exit & Save";
                                putStrLn "\nSelected option: "
                                option <- getLine
                                case option of 
                                     "1" -> do putStr "Name of Film: "
                                             title <- getLine
                                             putStr "Name of the Director: "
                                             director <- getLine
                                             putStr "Year the film was released: "
                                             year <- getLine
                                             putStrLn (map formatFilmOutput $ addFilm title director (read year) [] newDb)
                                     "2" -> do putStrLn (displayAllFilm newDb) >> menu newDb

1 个答案:

答案 0 :(得分:2)

“我尝试使用制表符和空格进行缩进,但没有成功。” - 这是你的问题。找到一个编辑器,在保存文件后,用空格替换制表符;或将制表位设置为8个字符。

Haskell报告,第10.3节:

Tab stops are 8 characters apart.
http://www.haskell.org/onlinereport/haskell2010/haskellch10.html#x17-17800010.3