【发布时间】:2014-03-14 02:08:48
【问题描述】:
我无法弄清楚为什么在编译代码时会出现解析错误。我尝试使用制表符和空格进行缩进,但没有成功。也许我只是需要另一双眼睛看代码,任何帮助将不胜感激!
错误似乎来自这一行:
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
【问题讨论】:
-
我在尝试时遇到不同的错误,它位于
title <- getLine线上。你碰巧在你的编辑器中使用标签吗? Haskell 允许混合它们,但标签不一定像您在编辑器中看到的那样被解析。 -
是的,我已经标记了所有内容,我可能在几行中使用了空格。刚刚再次测试它,当注释掉一切似乎都很好,但是当添加解析错误时再次出现。
-
在编辑器中找到将制表符替换为空格的设置。我保证它会让事情变得更容易。就像 Python 一样,可以使用制表符,但人们最终会遇到解析错误。
-
干杯我会试一试,但开始看到我的项目可能出现的其他问题,所以我将不得不回到这个
-
尝试在第一个while之前放一个空格,看看是否有效......
标签: haskell input formatting output