A在sequenceA中代表什么? [英] what does the A stand for in sequenceA?

查看:137
本文介绍了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]

引入ApplicativeTraversable时,该功能从列表推广到任何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)

sequenceMonad约束是不必要的约束.但是,那时还不能将其进一步推广到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中代表什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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