module Exercise_7 where import Data.List {-WETT-} tuplefilter :: Eq e => [(k,e)] -> (k -> k -> Bool) -> [(k,e)] tuplefilter xs f = aux xs [] [] f where aux [] fs bs f = fs++bs aux (x:xs) fs [] f = aux xs [] (x:fs) f aux (x:xs) fs (b:bs) f | snd x == snd b = if (f (fst x) (fst b)) then (aux xs [] (fs++[x]++bs) f) else (aux xs [] (fs++[b]++bs) f) | otherwise = aux (x:xs) (fs++[b]) bs f comp :: Eq b => [(Integer,(a,b))] -> [(Integer,(b,c))] -> [(Integer,(a,c))] comp xs ys = [(xi+yi, (xa, yb)) | (xi, (xa, xb)) <- xs, (yi, (ya, yb)) <- ys, xb == ya] subset [] ys = True subset (x:xs) ys = elem x ys && subset xs ys setEquality xs ys = subset xs ys && subset ys xs trancl :: Eq a => [(Integer,(a,a))] -> [(Integer,(a,a))] trancl xs = if (setEquality newval xs) then newval else trancl newval where newval = tuplefilter ((comp xs xs) ++ xs) (<) {-TTEW-}