containers icon indicating copy to clipboard operation
containers copied to clipboard

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

Open andreasabel opened this issue 1 year ago • 2 comments

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?

andreasabel avatar Jan 31 '24 15:01 andreasabel

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

Bodigrim avatar Jan 31 '24 22:01 Bodigrim

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.

treeowl avatar Feb 01 '24 00:02 treeowl