A在sequenceA中代表什么?

编程入门 行业动态 更新时间:2024-10-25 09:35:54
本文介绍了A在sequenceA中代表什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

Traversable的sequenceA代表什么?为什么末尾有大写字母A?我已经学习Haskell几个月了,这是困扰我一段时间的事情之一.

What does sequenceA from Traversable stand for? Why is there capital A at the end? I've been learning Haskell for a few months now and this is one of those things that's been bugging me for a while.

推荐答案

"A"代表Applicative,就像在sequenceA类型的约束中一样:

The "A" stands for Applicative, as in the constraint in sequenceA's type:

sequenceA :: (Traversable t, Applicative f) => t (f a) -> f (t a)

"A"存在是历史事故的结果.很久以前,和Traversable在Haskell中都不存在.尽管如此,已经存在一个与sequenceA完全一样的函数-区别在于它具有更具体的类型:

That the "A" is there is fruit of a historical accident. Once upon a time, neither Applicative nor Traversable existed in Haskell. Nonetheless, a function exactly like sequenceA already existed -- except that it had a much more specific type:

sequence :: Monad m => [m a] -> m [a]

引入Applicative和Traversable时,该功能从列表推广到任何Traversable [1]:

When Applicative and Traversable were introduced, the function was generalised from lists to any Traversable [1]:

sequence :: (Traversable t, Monad m) => t (m a) -> m (t a)

sequence的Monad约束是不必要的约束.但是,那时还不能将其进一步推广到Applicative.问题在于,直到去年初,Applicative都不是应有的Monad的超类,因此将签名推广到Applicative将会破坏对缺少实例.就是这样,在常规版本的名称中添加了一个额外的"A".

sequence's Monad constraint is unnecessarily restrictive. Back then, however, generalising it further to Applicative was not an option. The problem was that until early last year Applicative was not a superclass of Monad as it is supposed to be, and therefore generalising the signature to Applicative would break any use of sequence with monads that lacked an Applicative instance. That being so, an extra "A" was added to the name of the general version.

[1]:但是请注意,直到最近,《序曲》仍继续使用特定于列表的版本.

[1]: Note, however, that the Prelude continued to carry the list-specific version until quite recently.

更多推荐

A在sequenceA中代表什么?

本文发布于:2023-11-25 02:38:42,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1627988.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:代表   sequenceA

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!