这可能是一个愚蠢的问题,但我已经花了四个小时在我发布之前指出问题所在。haskell定义新类型
data Film = Film {title :: String
,name :: String
,year :: Int}
deriving (Show)
testDatabase :: [Film]
testDatabase = [ ("Blade Runner", "Ridley Scott",1982)]
--(i) Add new film to the database
addFilm :: String -> String -> Int -> [Film] -> [Film]
addFilm title director year film = film + Film title director year
--(ii) Give all film in the database
getFilm :: [Film]
getFilm = testDatabase
我想要做的是定义包含一个新的类型名称Film
:电影片名,电影导演和制作的一年。
Testdatabase
用于存储数据。
addFilm
是为数据库添加更多电影的功能。
getfilm
用于列印电影列表。
这是错误的样子。
coursework.hs:21:18:
Couldn't match expected type `Film'
with actual type `([Char], [Char], Integer)'
In the expression: ("Blade Runner", "Ridley Scott", 1982)
In the expression: [("Blade Runner", "Ridley Scott", 1982)]
In an equation for `testDatabase':
testDatabase = [("Blade Runner", "Ridley Scott", 1982)]
coursework.hs:24:43:
Couldn't match expected type `[Film]' with actual type `Film'
In the return type of a call of `Film'
In the second argument of `(+)', namely `Film title director year'
In the expression: film + Film title director year
Failed, modules loaded: none.
谢谢!!