我目前正在使用haskell 制作基于文本的菜单系统。我创建了一个名为 Book 的数据类型,其中每个函数都编辑列表并返回它。但是,我无法弄清楚如何使菜单部分工作,它可以编辑此列表并递归回来。
关于我卡在菜单上的示例,将一本书添加到列表中,然后菜单需要重新加载菜单,以便我可以显示新添加的书籍。
菜单示例
menu:: [Book] -> [IO]
menu books = do
str <- getLine
let selectNum = (read str :: Int)
case selectNum of
1 -> let sd = addNewBookIO books
2 -> displayAllBooksFromYear books
添加新书的示例
addNewBookIO :: [Book] -> IO [Book]
addNewBookIO films =
do putStr "Film name: "
filmTitle <- getLine
putStr "List all cahr in the Book (separated by commas): "
cast <- addToStringArray []
putStr "Year of Realese in the UK: "
year <- getLine
let test = (read year :: Int)
putStr "List all the fans(separated by commas): "
fans <- addToStringArray []
putStrLn "Your Book has been added"
let bookList = addbookFilm (Film bookTitle cast test fans) films
return bookList
任何帮助将不胜感激