这是我必须显示数据库信息的当前代码,但是当打印出来时,阅读起来不是很清楚..
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", "Kevin", "Tim"])]
运行此功能时:
displayAllFilms :: Database ->[(Title, [Cast], Year, [Fans])]
displayAllFilms [] = []
displayAllFilms ((i, j, k, l): xs)
|l == [] = (i, j, k, []) : displayAllFilms xs
|otherwise = (i, j, k, l) : displayAllFilms xs
它打印这个:
[("皇家赌场",["丹尼尔·克雷格","伊娃·格林","朱迪·丹奇"],2006 ["加里","戴夫","佐伊","凯文","艾玛"]),("牛仔与外星人”,[“哈里森福特”,“丹尼尔克雷格”,“奥利维亚王尔德”],2011,[“比尔”,“乔”,“加里”,“凯文”,“奥尔加”,“莉兹”]) ,(“如果可以的话,抓住我”,[“莱昂纳多·迪卡普里奥”,“汤姆·汉克斯”],2002,[“佐伊”,“海蒂”,“乔”,“艾玛”,“莉兹”,“山姆”,奥尔加","凯文","蒂姆"])]
这显然是不可读的:有没有办法让每个电影信息(在这种情况下)打印在单独的行上,即。使用 /n 符号?
帮助将不胜感激,在此先感谢!:)