Fix a bug that could cause "Prelude.head: empty list"

In Data.Operations, the function topoTest2 assumed too much about the form of
the input, compared to the older function topoTest.
This commit is contained in:
hallgren
2013-02-28 17:46:13 +00:00
parent 5e3e5821fb
commit e61f2f8d03

View File

@@ -266,8 +266,10 @@ topoTest = topologicalSort . mkRel'
-- | topological sorting with test of cyclicity, new version /TH 2012-06-26
topoTest2 :: Ord a => [(a,[a])] -> Either [[a]] [[a]]
topoTest2 g = maybe (Right cycles) Left (tsort g)
topoTest2 g0 = maybe (Right cycles) Left (tsort g)
where
g = g0++[(n,[])|n<-nub (concatMap snd g0)\\map fst g0]
cycles = findCycles (mkRel' g)
tsort nes =