Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what does the A stand for in sequenceA?

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.

like image 331
diminishedprime Avatar asked Jan 06 '23 04:01

diminishedprime


1 Answers

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.

like image 68
duplode Avatar answered Jan 13 '23 04:01

duplode