如果你拿你的代码:
addBook = do
putStrLn "Enter the title of the Book"
tit <- getLine
putStrLn "Enter the author of "++tit
aut <- getLine
putStrLn "Enter the year "++tit++" was published"
yr <- getLine
并将其“翻译”为“正常”(非do
)符号(给定p = putStrLn "..."
):
addBook =
p >> getLine >>= (\tit ->
p >> getLine >>= (\aut ->
p >> getLine >>= (yr ->
你最终(yr ->
没有意义。如果您没有其他有用的事情要做,则可以返回一个空元组:
return ()
在末尾:
addBook = do
putStrLn "Enter the title of the Book"
tit <- getLine
putStrLn "Enter the author of "++tit
aut <- getLine
putStrLn "Enter the year "++tit++" was published"
yr <- getLine
return ()
您可能应该问自己为什么需要获取aut
以及yr
尽管。