什么是Alternative的“一些”和“许多”对...有用? [英] What are Alternative's "some" and "many" useful for?
问题描述
替代
, Applicative
的扩展名,声明空
,< |>
以及这两个函数:
lockquote
一个或多个 p>
some :: fa - > f [a]
零或多:
many :: fa - >如果被定义,一些
>和>许多
应该是方程的最小解:
some v =(:)< $> v *许多v
许多v =某些v< |> pure []
我无法找到一些
和许多
被定义。 它们的含义和实际用途是什么?它们是否被使用?我一直无法从这个定义中理解它们的用途。
更新:我不问什么是另类
,只是一些
和多
我倾向于在
Applicative
解析器组合器库中看到它们。 a :: Parser [String]
a = some(stringhello)
,我发现 many
用于中的解析
的默认定义
我认为Parsec是解析器组合器库的主要例子,隐藏了因为它重新定义了诸如
/ (< |>)
之类的东西。 many
p>
Alternative
, an extension of Applicative
, declares empty
, <|>
and these two functions:
One or more:
some :: f a -> f [a]
Zero or more:
many :: f a -> f [a]
If defined,
some
andmany
should be the least solutions of the equations:some v = (:) <$> v <*> many v many v = some v <|> pure []
I couldn't find an instance for which some
and many
are defined. What is their meaning and practical use? Are they used at all? I've been unable to grasp their purpose just from this definition.
Update: I'm not asking what is Alternative
, just what are some
and many
I tend to see them in Applicative
parser combinator libraries.
a :: Parser [String]
a = some (string "hello")
and I see many
used for purpose in the default definitions of Parsing
in parsers
.
I think Parsec being the primary example of a parser combinator library hides the use of some
/many
since it redefines things like (<|>)
.
这篇关于什么是Alternative的“一些”和“许多”对...有用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!