module Exercise_7 where import Data.List {-WETT-} comp :: Eq b => [(Integer,(a,b))] -> [(Integer,(b,c))] -> [(Integer,(a,c))] comp xs ys = [(x + y, (a,d))|(x, (a,b)) <- xs, (y,(c,d)) <- ys, b == c] trancl :: Eq a => [(Integer,(a,a))] -> [(Integer,(a,a))] trancl xs = filt (sortOn fst (trans xs 4)) where filt [] = [] filt ((m,(a,b)):xs) = if (elem (a,b) (snd (unzip xs))) then [(m,(a,b))] ++ (filt [(n,(c,d))| (n,(c,d)) <- xs, (c,d) /= (a,b)]) else [(m,(a,b))] ++ (filt xs) trans xs a = if a == 0 || null (comp xs xs) then xs else trans (filt (sortOn fst (xs ++ (comp xs xs)))) (a-1) {-TTEW-}