commercialhaskell / rio

A standard library for Haskell
Other
838 stars 54 forks source link

Switch from []-specific to Functor-general unzip? #172

Open akhra opened 5 years ago

akhra commented 5 years ago

Odd thing I just discovered: the default Prelude and RIO.Prelude both have

unzip :: [(a, b)] -> ([a], [b])

...but Data.List.NonEmpty provides

unzip :: Functor f => f (a, b) -> (f a, f b)

This feels like it just got left behind during FTP, are there any arguments against generalizing it?

snoyberg commented 5 years ago

Looking at the implementation, I have a feeling that the generalized unzip may have negative performance implications, and that's why it wasn't generalized in Prelude:

-- | The 'unzip' function is the inverse of the 'zip' function.
unzip :: Functor f => f (a,b) -> (f a, f b)
unzip xs = (fst <$> xs, snd <$> xs)

Before making this change in rio, I'd like to hear why it wasn't included as part of FTP. If it's just an oversight, then I'm OK with the change.

akhra commented 5 years ago

As a counterpoint, the specialized version is also exported from Data.List (and RIO.List) so it remains available. Granted, this doesn't negate the concern about a surprising performance cost -- even if we document it, how many people are going to check the docs before using unzip?