haskell / containers

Assorted concrete container types

Home Page:https://hackage.haskell.org/package/containers

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

andreasabel opened this issue · comments

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?

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

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.