我需要用高阶函数重新制作这个函数。我不知道如何改变lookupTitle
,但另一个我已经改变了。但我在bookAuthors
上收到了错误。
type Title = String
type Author = String
data Product = Book Title Author
| Video Author
| CD Title Integer Author
deriving (Eq,Show)
getTitle (Book title _ ) = title
getTitle (Video title ) = title
getTitle (CD title _ _ ) = title
getTitles l = map (\x->getTitle x) l
lookupTitle _ [] = Nothing
lookupTitle x (y:ys) | getTitle y == x = Just y
| otherwise = lookupTitle x ys
lookupTitles a b = map (\x->lookupTitle x b) a
bookAuthors l = filter author l
where author (Book _ _) = True
author _ = False
为什么?