什么是替代的“一些"?和“许多"对...有用? [英] What are Alternative's "some" and "many" useful for?

查看:29
本文介绍了什么是替代的“一些"?和“许多"对...有用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

替代方案Applicative的扩展,声明了empty<|>和这两个函数:><块引用>

一个或多个:

some :: f a ->F A]

零个或多个:

many :: f a ->F A]

如果定义了,somemany 应该是方程的最小解:

some v = (:) <$>v <*>许多 v许多 v = 一些 v <|>纯的 []

我找不到定义了 somemany 的实例.它们的含义和实际用途是什么?它们是否被使用过?我一直无法从这个定义中理解它们的目的.

更新:我不是在问什么是Alternative,而是somemany>

解决方案

我倾向于在 Applicative 解析器组合器库中看到它们.

a :: 解析器 [字符串]a = some(字符串你好")

我看到 many 用于 parsersParsing 的默认定义.

我认为 Parsec 作为解析器组合器库的主要示例隐藏了 some/many 的使用,因为它重新定义了诸如 (<|>).

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 and many 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 (<|>).

这篇关于什么是替代的“一些"?和“许多"对...有用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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