字符 \US 处出现词汇错误
我需要用高阶函数重新制作这个函数。我不知道如何更改 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
为什么?
I need to remake this functions with high order functions. I don't know how to change lookupTitle
but the other I've already changed. But I've got an error on 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
Why?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
看起来像是缩进问题。 这编译没有错误。
Looks like an indentation problem. This compiles without errors.