我目前有一个包含以下信息的数据库:
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]
title (t, _, _, _) = t
fans (_, _, _, fs) = fs
year (_, _, y, _) = y
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", "Kevin", "Tim"]),
("Mamma Mia!", ["Meryl Streep", "Pierce Brosnan"], 2008, ["Kevin", "Jo", "Liz", "Amy", "Sam", "Zoe"]),
("Saving Private Ryan", ["Tom Hanks", "Matt Damon"], 1998, ["Heidi", "Jo", "Megan", "Olga", "Zoe", "Wally"]),
("Life of Pi" ,["Suraj Sharma"], 2012, ["Kevin", "Olga", "Liz", "Tim", "Zoe", "Paula", "Jo", "Emma"])]
注意: testDatabase 包含更多数据,我只包含了其中的一个片段。
现在我的目标是写一个函数,让我根据粉丝的数量“展示最好的电影”。
我曾尝试使用“长度粉丝”来输出每部电影的粉丝数量,但我不知道如何绕过然后输出“最佳电影”的标题
这是 displayAllFilms 的示例代码:
displayAllFilms' :: [Film] -> String -> String
displayAllFilms' [] filmString = filmString
displayAllFilms' ((title,cast,year,fans):films) filmString =
displayAllFilms' films (filmString ++ "\n" ++ title ++ ", " ++ listStuff cast ", " ++ (show year) ++ ", " ++ show (length fans))
它输出每部电影的粉丝数量......
编辑:
我忘了说这个功能需要用户输入一个演员的名字,然后根据电影的粉丝数量和演员出演的电影输出最好的电影。
任何帮助将不胜感激,谢谢!