应用(和朋友)方法是否有人类友好的名称?

发布于 2024-11-04 00:57:30 字数 1455 浏览 1 评论 0原文

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

猫烠⑼条掵仅有一顆心 2024-11-11 00:57:30

该符号来自 Doaitse Swierstra 和 Luc Duponcheel:他们已经为解析器组合器确定了这个接口,我们认为尊重他们的选择是很重要的,因为这样做是有意义的。我试图记住Doaitse如何发音,但一片空白。

我更喜欢他们被看到而不是被听到。事实上,我也不希望看到它们,因此 成语括号。但特别是在定义实例时,拥有名称会很有帮助。这并不是说由我来命名它们:整个习语与应用与天知道是什么恶作剧是对权力的迷人研究。就其价值而言,用我自己的话来说

  • <*> 是“应用(到)”(界面是“纯粹且应用的”,就像数学一样)
  • *> 是“忽略”
  • <* 是“忽略”
  • <$> 是“映射(覆盖)”
  • <$ 可能是'之后',但我不太有意识地称呼它任何东西

关键思想:效果总是从左到右排序(无论这意味着什么); $ 或 * 告诉您左边的内容是纯粹的还是惯用的; V 形告诉您生成的数据流,仅指向信号。

另一种发音方案(与各个操作员相差一个级别)可能会翻译

f <
gt; a <*> b <* c <*> d

为“IDIOM:f、a、b、NOISE c、d”或类似的内容。但这实际上是

(|f a b (-c-) d|)

大声朗读括号版本。

我觉得“金钱”和“splat”很有趣,但我们最好优先考虑语义而不是语法的问题。

The notation comes from Doaitse Swierstra and Luc Duponcheel: they had already identified this interface for parser combinators, and we felt it was important to respect their choices where it was meaningful to do so. I'm trying to remember how Doaitse pronounces them, but drawing a blank.

I prefer them to be seen and not heard. In fact, I prefer them not to be seen either, hence idiom brackets. But especially when defining an instance, it's helpful to have names. Not that it's down to me to name them: the whole Idiom vs Applicative vs goodness-knows-what shenanigans was a fascinating study of power. For what it's worth, in my own parlance

  • <*> is 'applied (to)' (the interface is 'pure and applied', like mathematics)
  • *> is 'ignored'
  • <* is 'ignoring'
  • <$> is 'mapped (over)'
  • <$ is perhaps 'after', but I'm not terribly conscious of calling it anything

The key ideas: the effects always sequence (whatever that means) left-to-right; the $ or * tell you whether what's to their left is pure or idiomatic; the chevrons tell you the resulting dataflow, pointing only to the signal.

An alternative pronunciation scheme, a level away from the individual operators, might translate

f <
gt; a <*> b <* c <*> d

to 'IDIOM: f, a, b, NOISE c, d' or some such. But that's really reading the bracket version

(|f a b (-c-) d|)

out loud.

I find 'money' and 'splat' amusing, but we might do well to prioritize semantics over asciidents of syntax.

瞎闹 2024-11-11 00:57:30

嗯,<$>fmap 的同义词。另外,“应用”这个名字让我想到应用事物。由于 <*> 是执行此操作的主要运算符,因此我认为我将其与“apply”一词松散地联系起来。上下文与正常的函数应用程序略有不同,因此该词可能会有些混淆,但上下文通常足够清楚,所以它对我有用。 <*> 也是 Control.Monad 中 ap 函数的同义词,因此这证实了我对“apply”一词的使用。

Brent Yorgey 的 Typeclassopedia 是我学到大部分内容的地方。这是一个优秀的资源。

Well, <$> is a synonym for fmap. Also, the name "applicative" makes me think of applying things. Since <*> is the main operator for doing that, I think I associate it loosely with the word "apply". The context is slightly different from normal function application so there could be some confusion with that word, but the context usually makes it clear enough, so it works for me. <*> is also a synonym for the ap function from Control.Monad, so this confirms my use of the word "apply".

Brent Yorgey's Typeclassopedia is where I learned most of this. It's an outstanding resource.

梦罢 2024-11-11 00:57:30

好吧,没有标准名称,但有时它们被称为:

  • <*> 是“splat”
  • <$> 是“money”

,这样:

 f <
gt; g <*> x

发音为:

 f `money` g `splat` x

我相信这些术语是由 Trevor Elliott 和 Eric Mertens 提出的。

Well, there's no standard names, but sometimes they're referred to as:

  • <*> is "splat"
  • <$> is "money"

such that:

 f <
gt; g <*> x

is pronounced:

 f `money` g `splat` x

Terms originated by Trevor Elliott and Eric Mertens, I believe.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文