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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With