我想製作一個函數,返回給定範圍內的電影列表。例如,假設我有電影的名單,我想找到的是,在幾年冒出來的所有的電影2010年至2014年,這裏是我的代碼:非窮舉模式:Int - > Int - > [電影] - > [電影]
type Rating = (String, Int)
type Title = String
type Director = String
type Year = Int
type Film = (Title, Director, Year,[Rating])
testDatabase :: [Film]
testDatabase = [("Blade Runner","Ridley Scott",1982,[("Amy",5), ("Bill",8), ("Ian",7), ("Kevin",9), ("Emma",4), ("Sam",7), ("Megan",4)]),
("The Fly","David Cronenberg",1986,[("Megan",4), ("Fred",7), ("Chris",5), ("Ian",0), ("Amy",6)]),
("Psycho","Alfred Hitchcock",1960,[("Bill",4), ("Jo",4), ("Garry",8), ("Kevin",7), ("Olga",8), ("Liz",10), ("Ian",9)]),
("Body Of Lies","Ridley Scott",2008,[("Sam",3), ("Neal",7), ("Kevin",2), ("Chris",5), ("Olga",6)]),
("Avatar","James Cameron",2009,[("Olga",1), ("Wally",8), ("Megan",9), ("Tim",5), ("Zoe",8), ("Emma",3)]),
("Titanic","James Cameron",1997,[("Zoe",7), ("Amy",1), ("Emma",5), ("Heidi",3), ("Jo",8), ("Megan",5), ("Olga",7), ("Tim",10)]),
("The Departed","Martin Scorsese",2006,[("Heidi",3), ("Jo",8), ("Megan",5), ("Tim",3), ("Fred",5)]),
("Aliens","Ridley Scott",1986,[("Fred",9), ("Dave",6), ("Amy",10), ("Bill",7), ("Wally",1), ("Zoe",5)]),
("Kingdom Of Heaven","Ridley Scott",2005,[("Garry",3), ("Chris",7), ("Emma",5), ("Bill",1), ("Dave",3)]),
("E.T. The Extra-Terrestrial","Steven Spielberg",1982,[("Ian",9), ("Amy",1), ("Emma",7), ("Sam",8), ("Wally",5), ("Zoe",6)]),
("Bridge of Spies","Steven Spielberg",2015,[("Fred",3), ("Garry",4), ("Amy",10), ("Bill",7), ("Wally",6)]),
("Vertigo","Alfred Hitchcock",1958,[("Bill",8), ("Emma",5), ("Garry",1), ("Kevin",6), ("Olga",6), ("Tim",10)]),
("The Birds","Alfred Hitchcock",1963,[("Garry",7), ("Kevin",8), ("Olga",4), ("Tim",8), ("Wally",3)]),
("Jaws","Steven Spielberg",1975,[("Fred",3), ("Garry",0), ("Jo",3), ("Neal",9), ("Emma",7)]),
("The Martian","Ridley Scott",2015,[("Emma",7), ("Sam",8), ("Wally",5), ("Dave",10)]),
("The Shawshank Redemption","Frank Darabont",1994,[("Jo",8), ("Sam",10), ("Zoe",4), ("Dave",7), ("Emma",3), ("Garry",10), ("Kevin",7)]),
("Gladiator","Ridley Scott",2000,[("Garry",7), ("Ian",4), ("Neal",5), ("Wally",3), ("Emma",4)]),
("The Green Mile","Frank Darabont",1999,[("Sam",3), ("Zoe",4), ("Dave",7), ("Wally",5), ("Jo",5)]),
("True Lies","James Cameron",1994,[("Dave",3), ("Kevin",10), ("Jo",0)]),
("Super 8","J J Abrams",2011,[("Dave",7), ("Wally",3), ("Garry",5), ("Megan",4)]),
("Minority Report","Steven Spielberg",2002,[("Dave",6), ("Garry",6), ("Megan",2), ("Sam",7), ("Wally",8)]),
("War Horse","Steven Spielberg",2011,[("Dave",6), ("Garry",6), ("Megan",3), ("Sam",7), ("Wally",8), ("Zoe",8)]),
("The Terminal","Steven Spielberg",2004,[("Olga",8), ("Heidi",8), ("Bill",2), ("Sam",6), ("Garry",8)]),
("Star Wars: The Force Awakens","J J Abrams",2015,[("Olga",6), ("Zoe",6), ("Bill",9), ("Sam",7), ("Wally",8), ("Emma",8)]),
("Hugo","Martin Scorsese",2011,[("Sam",9), ("Wally",3), ("Zoe",5), ("Liz",7)])]
filmsInRangeOfYears :: Int -> Int -> [Film] -> [Film]
filmsInRangeOfYears _ _ [] = []
filmsInRangeOfYears minYear maxYear [(title, director, year, rating)] = filter(\(_,_,year,_) -> year >= minYear && year <=maxYear) [(title, director, year, rating)]
但是,我一直recieving這個錯誤
**Non-exhaustive patterns in function filmsInRangeOfYears**
環顧在線後,我仍然不明白如何解決這個錯誤;從我的理解我需要更多的模式來填補所有可能的案例,但我用過的仍然給了我相同的結果。如果有人能幫助我,這我會很greatfull
編輯:增加了電影
的一個例子列表
你能想到'filmsInRangeOfYears'的示例輸入與你寫的任何一種模式都不匹配嗎? –
@IanHenry你好嗎 – hao