Haskell - Control.Applicative.Alternative 有什么用?
我正在查看 Haskell 库中的 Applicative 类,并偶然发现了 替代
。
这门课有什么用?谷歌搜索没有发现任何特别有见地的东西。它似乎完全不合适,因为它与 Applicative 包捆绑在一起。
有人可以发布一个您将使用此类的可能场景吗?
I was looking at the Applicative
class within Haskell libraries and stumbled across Alternative
.
What is this class good for? A google search did not reveal anything particularly insightful. And it seems to be completely out of place, bundled as it is with the Applicative package.
Could someone please post a possible scenario where you would use this class?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
它通常与解析器组合器一起使用。例如,如果
space
是匹配单个空白字符的解析器组合器,则many space
将是匹配连续空白的组合器。不过,我同意它在
Control.Applicative
中有点不合适。It's commonly used with parser combinators. For example, if
space
is a parser combinator that matches a single whitespace character,many space
would be one that would match consecutive whitespace.I can agree that it's slightly out of place in
Control.Applicative
, though.有时
<|>
运算符非常有用:Sometimes the
<|>
operator is quite useful: