Topological sort: Difference between revisions
→{{header|Haskell}}: Pruned and specified imports, applied hlint and hindent, added type signature.
m (→{{header|REXX}}: changed case of spelling,) |
(→{{header|Haskell}}: Pruned and specified imports, applied hlint and hindent, added type signature.) |
||
Line 2,441:
=={{header|Haskell}}==
<lang haskell>import Data.List ((\\), elemIndex, intersect, nub)
import
combs 0 _ = [[]]
combs _ [] = []
combs k (x:xs) =
depLibs :: [(String, String)]
depLibs =
[ ( "des_system_lib"
, "std synopsys std_cell_lib des_system_lib
, ("dw03", "std synopsys dware dw03 dw02
, ("std_cell_lib", "ieee std_cell_lib")
, ("synopsys", [])
]
toposort :: [(String, String)] -> [String]
toposort xs
error $ "Dependency cycle detected for libs " ++ show cycleDetect
where
nub $
Just i -> uncurry(++) $ first(++xs) $ splitAt i ts▼
case elemIndex x ts of
_ -> ts ++ xs ++ [x]▼
cycleDetect =
combs 2 dB
main :: IO ()
▲ cycleDetect = filter ((>1).length)
main = print $ toposort depLibs</lang>
▲ $ map (\[(a,as), (b,bs)] -> (a `intersect` bs) ++ (b `intersect`as))
{{out}}
<lang haskell>*Main> toposort depLibs
|