module Exercise_7 where import Data.List {-WETT-} comp :: Eq b => [(Integer,(a,b))] -> [(Integer,(b,c))] -> [(Integer,(a,c))] comp [] relB = [] comp ( (n,(a,b)) :relA) relB = [(n+m,(a,d)) | (m,(c,d)) <- relB, b==c] ++ comp relA relB trancl :: Eq a => [(Integer,(a,a))] -> [(Integer,(a,a))] trancl = tranclAcc [] tranclAcc acc rel = if c==acc then acc else tranclAcc c rel where c = nubBy (\(n,(a,b)) (m,(c,d)) -> a==c && b==d) (sortBy (\(n,_) (m,_) -> compare n m) (comp acc rel ++ acc ++ rel)) {-TTEW-}