Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
akhra opened this issue Apr 26, 2019 · 2 comments
Open

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

akhra opened this issue Apr 26, 2019 · 2 comments

Comments

@akhra
Copy link
Collaborator

akhra commented Apr 26, 2019

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
Copy link
Collaborator

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
Copy link
Collaborator Author

akhra commented Apr 28, 2019

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?

@akhra akhra mentioned this issue May 3, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants