Proposal: Move `mapM` and `sequence` out of Traversable

Alexey Kuleshevich alexey at kuleshevi.ch
Sat Nov 7 20:27:51 UTC 2020


Hi Emily,

As David suggested, removal of `mapM` will be problematic for boxed `Vector`: https://github.com/haskell/vector/blob/a15a52155f281ca6753ecef1247f84a0579e3123/Data/Vector.hs#L468-L478
The reason behind that fact is that streams in `vector` are monadic, so `traverse` implementation has to go through a list, while `mapM` can be implemented in a more efficient manner.

My personal opinion on this is that such slimming of Traversable is counterproductive, the only thing we incur is a bunch of broken libraries and redundant work on maintainers part.
Is there anything that can be won from a user's perspective from such a change? A potential performance or usability benefit that I am missing?

Sincerely,
Alexey.

‐‐‐‐‐‐‐ Original Message ‐‐‐‐‐‐‐
On Saturday, November 7, 2020 11:03 PM, David Feuer <david.feuer at gmail.com> wrote:

> I'm generally in favor of removing `sequence`, and probably also `sequenceA`. Can you demonstrate that there can be no instance for which `mapM` is much more efficient than `traverse`? Consider especially types based on monadic streams.
>
> On Sat, Nov 7, 2020 at 2:56 PM Emily Pillmore <emilypi at cohomolo.gy> wrote:
>
>> Hi All,
>>
>> I have a proposal for the `base` library: I would like to move `mapM` and `sequence` out of the class definition for `Traversable`, redefining them as toplevel aliases:
>>
>> ```haskell
>> mapM :: Traversable t ⇒ Monad m ⇒ (a -> m b) -> t a -> m (t b)
>> mapM = traverse
>>
>> sequence :: Traversable t ⇒ Monad m=> t (m a) -> m (t a)
>> sequence = sequenceA
>> ```
>>
>> This slims `Traversable` by 50%. This would be a very small breaking change, which is completely tractable, but a great improvement for the ecosystem imo. Thoughts? What timeline should we shoot for with a change like this?
>>
>> Cheers,
>> Emily
>>
>> _______________________________________________
>> Libraries mailing list
>> Libraries at haskell.org
>> http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/libraries/attachments/20201107/9ec7b459/attachment.html>


More information about the Libraries mailing list