字符 \US 处出现词汇错误

发布于 2024-12-11 01:45:59 字数 799 浏览 0 评论 0原文

我需要用高阶函数重新制作这个函数。我不知道如何更改 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

鸠书 2024-12-18 01:45:59

看起来像是缩进问题。 编译没有错误。

Looks like an indentation problem. This compiles without errors.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文