这是我必须显示一个有价值信息数据库的当前代码,但是当打印出来时,阅读它并不是很清楚.
type Title = String
type Cast = String
type Year = Int
type Fans = String
type Film = (Title, [Cast], Year, [Fans])
type Database = [Film]
testDatabase :: Database
testDatabase = [("Casino Royale", ["Daniel Craig", "Eva Green", "Judi Dench"], 2006, ["Garry", "Dave", "Zoe", "Kevin", "Emma"]),
("Cowboys & Aliens", ["Harrison Ford", "Daniel Craig", "Olivia Wilde"], 2011, ["Bill", "Jo", "Garry", "Kevin", "Olga", "Liz"]),
("Catch Me If You Can", ["Leonardo DiCaprio", "Tom Hanks"], 2002, ["Zoe", "Heidi", "Jo", "Emma", "Liz", "Sam", "Olga", …Run Code Online (Sandbox Code Playgroud) 我想写的功能是让用户输入他们的名字和他们想成为粉丝的电影.
这是我正在使用的当前代码:
type Title = String
type Actor = String
type Cast = [Actor]
type Year = Int
type Fan = String
type Fans = [Fan]
type Period = (Year, Year)
type Film = (Title, Cast, Year, Fans)
type Database = [Film]
testDatabase :: Database
testDatabase = [("Casino Royale", ["Daniel Craig", "Eva Green", "Judi Dench"], 2006, ["Garry", "Dave", "Zoe", "Kevin", "Emma"]),
("Cowboys & Aliens", ["Harrison Ford", "Daniel Craig", "Olivia Wilde"], 2011, ["Bill", "Jo", "Garry", "Kevin", "Olga", "Liz"]),
("Catch Me If …Run Code Online (Sandbox Code Playgroud) 我想要做的是将我已经创建的函数调用到输入输出main.函数im调用是一个高阶函数,如下所示:
filmsByFan' f = map title $ filter (elem f . fans) testDatabase
Run Code Online (Sandbox Code Playgroud)
每当我尝试调用这个更高阶函数时,这就是吐出错误消息的代码部分:
getInt :: IO Int
getInt = do str <- getLine
return (read str :: Int)
main :: IO ()
main = do putStrLn "Enter 1. Add Film / 2. Display all Films / 3. Display film by Year / 4. Display film by fan / 5. Display film by actor and period / 6. Become Fan: "
str <- getLine
if str == "1"
then do …Run Code Online (Sandbox Code Playgroud)