我需要重新制作這個函數與高階函數。我不知道如何改變lookupTitle
,但其他我已經改變。但是我在bookAuthors
上發生了錯誤。字符錯誤在charcter 美國
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
爲什麼?
您應該提供更多的上下文。你想要做什麼,你期望得到什麼結果,你得到的錯誤是什麼? –
正如Mikhail Glushenkov指出的那樣,您的問題是縮進,請看下面的鏈接,瞭解縮放在Haskell中的工作原理:http://en.wikibooks.org/wiki/Haskell/Indentation – HaskellElephant