Haskell - 什么是Control.Applicative.Alternative对吗? [英] Haskell - What is Control.Applicative.Alternative good for?

查看:161
本文介绍了Haskell - 什么是Control.Applicative.Alternative对吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在查看Haskell库中的 Applicative 类,并偶然发现 Alternative

I was looking at the Applicative class within Haskell libraries and stumbled across Alternative.

这个课程有什么好处?谷歌搜索没有透露任何特别有见地的东西。它似乎是完全不合适的,因为它与Applicative包捆绑在一起。

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?

推荐答案

它通常与解析器组合器一起使用。例如,如果 space 是一个匹配单个空格字符的解析器组合符,那么多个空格将会匹配连续的空格。

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.

虽然我可以同意它在 Control.Applicative 中稍微不合适。

I can agree that it's slightly out of place in Control.Applicative, though.

这篇关于Haskell - 什么是Control.Applicative.Alternative对吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆