what does the A stand for in sequenceA?

我们两清 提交于 2019-12-20 01:14:20

问题


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.


回答1:


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

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

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]

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'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]: Note, however, that the Prelude continued to carry the list-specific version until quite recently.



来源:https://stackoverflow.com/questions/40181086/what-does-the-a-stand-for-in-sequencea

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!