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

Add flattenSCC1 : SCC vertex -> Data.List.NonEmpty.NonEmpty vertex #985

Open
andreasabel opened this issue Jan 31, 2024 · 2 comments · May be fixed by #987
Open

Add flattenSCC1 : SCC vertex -> Data.List.NonEmpty.NonEmpty vertex #985

andreasabel opened this issue Jan 31, 2024 · 2 comments · May be fixed by #987

Comments

@andreasabel
Copy link
Member

andreasabel commented Jan 31, 2024

The flattenSCC function throws away the knowledge that a SCC is a non-empty list of vertices:

-- | The vertices of a strongly connected component.
flattenSCC :: SCC vertex -> [vertex]
flattenSCC (AcyclicSCC v) = [v]
flattenSCC (NECyclicSCC vs) = NE.toList vs

In course of the new x-partial warning of GHC 9.8, this is a bit inconvenient, since GHC will now cry about head . flattenSCC and similar.

The more correct type of flattenSCC is SCC vertex -> Data.List.NonEmpty.NonEmpty vertex, but in order not to break everyone's code I suggest to add a new function flattenSCC1 instead.

Should this maybe have gone into containers-0.7?

@Bodigrim
Copy link
Contributor

@andreasabel one workaround is to use Data.Foldable1.toNonEmpty, there is an instance.

@treeowl
Copy link
Contributor

treeowl commented Feb 1, 2024

I don't have a strong opinion either way. I'd lean toward adding the function because it seems a bit odd to give the less informative version its own name but not the more informative one.

andreasabel added a commit that referenced this issue Feb 2, 2024
This gives a more precise type to the existing `flattenSCC :: SCC a -> [a]`.
Closes #985.
@andreasabel andreasabel linked a pull request Feb 2, 2024 that will close this issue
andreasabel added a commit that referenced this issue Feb 2, 2024
This gives a more precise type to the existing `flattenSCC :: SCC a -> [a]`.
Closes #985.
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

Successfully merging a pull request may close this issue.

3 participants