module Exercise_7 where import Data.List {-WETT-} minRelations :: Eq a => [(Integer, (a, a))] -> [(Integer, (a, a))] minRelations xs = nubBy (\(n1, (a1, b1)) (n2, (a2, b2)) -> a1 == a2 && b1 == b2) (sortBy (\(n1, a1) (n2, a2) -> compare n1 n2) xs) comp :: Eq b => [(Integer,(a,b))] -> [(Integer,(b,c))] -> [(Integer,(a,c))] comp fs gs = [(n1 + n2, (fa, gc)) | (n1, (fa, fb)) <- fs, (n2, (gb, gc)) <- gs, fb == gb] trancl :: Eq a => [(Integer,(a,a))] -> [(Integer,(a,a))] trancl xs = tranclRec (minRelations xs) where tranclRec xs | minRelations (xs ++ comp xs xs) == xs = xs | otherwise = tranclRec (minRelations (xs ++ comp xs xs)) {-TTEW-}