我試着運行這段代碼,但我發現在輸入解析錯誤‘讓’上:哈斯克爾解析輸入錯誤'讓」
let database = tempFilm:database
我無法找到問題的所在,可以你看看嗎?
options 7 (username, database) = do putStrLn "******************"
putStrLn " Rate a film "
putStrLn "******************"
putStrLn ""
putStr "Enter the title of the film or nothing to return to the main menu: "
title <- getLine
if title == ""
then return(username, database)
else do let filmCheck = findFilm title database
if filmCheck == []
then do putStrLn "That film does not exists."
return (username, database)
else do putStr "Enter your rate: "
tempRate <- getLine
case reads tempRate :: [(Integer, String)] of
[(n, "")] -> do let rate = read tempRate :: Int
let tempFilm = rateFilm username (username, rate) filmCheck
if checkIfRated username tempFilm == True
then do putStrLn "You already voted for this film\n"
putStrLn "Do you want to modify your voted?\n"
putStrLn "Press y to modify or nothing to return to the main menu:"
input <- getLine
if input /= "y"
then return (username, database)
else putStrLn "Your vote will be modified."
let database = tempFilm:database
putStrLn "You rating has been sumbited successfully!"
putStrLn (displayFilm tempFilm)
return (username, database)
編輯: 使用時
options 7 (username, database) = do putStrLn "******************"
putStrLn " Rate a film "
putStrLn "******************"
putStrLn ""
putStr "Enter the title of the film or nothing to return to the main menu: "
title <- getLine
if title == ""
then return(username, database)
else do let filmCheck = findFilm title database
if filmCheck == []
then do putStrLn "That film does not exists."
return (username, database)
else do putStr "Enter your rate: "
tempRate <- getLine
case reads tempRate :: [(Integer, String)] of
[(n, "")] -> do let rate = read tempRate :: Int
let tempFilm = rateFilm username (username, rate) filmCheck
when (checkIfRated username tempFilm == True) $
do putStrLn "You already voted for this film\n"
putStrLn "Do you want to modify your vote?\n"
putStrLn "Press y to modify or nothing to return to the main menu:"
input <- getLine
if input /= "y"
then return (username, database)
else putStrLn "Your vote will be modified."
let database = tempFilm:database
putStrLn "You rating has been sumbited successfully!"
putStrLn (displayFilm tempFilm)
return (username, database)
我的語法可能不正確我以前從來沒有
感謝您的回覆Aaron。有沒有辦法寫一個if語句沒有別的? like(if A then blah blah) – Bobys
@ user3207652:在do-block中,您可以使用['when'](http://hackage.haskell.org/package/base/docs/Control-Monad.html#v :什麼時候),例如'當cond $做...' – hammar
它給出一個關於「何時」不在範圍內的錯誤 – Bobys