haskell / containers

Assorted concrete container types
https://hackage.haskell.org/package/containers
314 stars 177 forks source link

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

Open andreasabel opened 5 months ago

andreasabel commented 5 months ago

The flattenSCC function throws away the knowledge that a SCC is a non-empty list of vertices: https://github.com/haskell/containers/blob/a4e8d167c0c0f0001e48f499d33735a61c68d9d4/containers/src/Data/Graph.hs#L248-L251

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 commented 5 months ago

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

treeowl commented 5 months ago

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.