我想要做的是将我已经创建的函数调用到输入输出主函数中。im 调用的函数是一个高阶函数,如下所示:
filmsByFan' f = map title $ filter (elem f . fans) testDatabase
这是每当我尝试调用这个高阶函数时吐出错误消息的代码部分:
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 return ()
else if str == "2"
then do putStrLn (displayAllFilms' testDatabase "")
else if str == "3"
then do putStrLn "Enter a film year: "
filmyear <- getInt
putStrLn (filmsByYear' filmyear) <<< **ERROR HERE** (154:47)
else main
直到这里的其余代码都可以正常工作,即如果用户输入“2”,它将运行 displayAllFilms 函数(注意 displayAllFilms 函数不是高阶函数)
是因为该功能是“高阶”,因此会出现此错误吗?
Coursework v1.hs:154:47:
Couldn't match expected type `Char' with actual type `[Char]'
Expected type: String
Actual type: [Title]
In the return type of a call of `filmsByYear''
In the first argument of `putStrLn', namely
`(filmsByYear' filmyear)'
任何帮助将非常感激!提前致谢!