Haskell:一些和许多 [英] Haskell: some and many
本文介绍了Haskell:一些和许多的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Control.Applicative.Alternative $ c中某些
和多
$ c>好吗?如果我写了某些$ Just 42
之类的东西,它似乎会导致无限递归,这似乎不是非常有用...... 解决方案当用作解析器组合器时,它们是有意义的。 某些
表示解析器尽可能经常应用,但至少应用一次。 many
类似,但不允许解析。如果可能
, Just ...
永远不会失败,因此解析器会循环。
What are some
and many
in Control.Applicative.Alternative
good for? If I write something like some $ Just 42
, it seems to cause infinite recursion, which seems not very useful...
解决方案 They make sense, when used as a parser combinator. some
means, that the parser is applied as often as possible, but at least once. many
is similar, but allows no parse. In case of Maybe
, Just ...
never "fails", thus your parser loops.
这篇关于Haskell:一些和许多的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文