blob: 3e8fe2e0d074024caf577fdfd0f9737cdf408d3b (
plain) (
tree)
|
|
import Data.List (partition)
cycle' :: Eq a => a -> [(a, a)] -> [[a]]
cycle' s edges = map reverse $ cycle'' s edges [s] False
where
cycle'' u edges path f
| f && u == s = [path]
| otherwise =
do let (vs, edges') = partition ((== u) . fst) edges
(_, v) <- vs
cycle'' v edges' (v:path) True
|