{-# LANGUAGE ExplicitForAll #-} module Exercise_7 where import Control.Monad import Data.List import Data.Functor import Data.Function (on, fix, (&)) import Text.Parsec (string, choice, char, try, sepBy1, noneOf, many1, parse, eof, optional, many) import Text.Parsec.String (Parser) import qualified Data.Set as Set {-WETT-} into' :: Eq b => Ord a => [(a, b)] -> (a, b) -> [(a, b)] into' [] = pure into' (f:fs) = \v -> if snd v == snd f then (fst v `min` fst f, snd v) : fs else f : into' fs v trancl' :: Eq a => [(Integer,(a,a))] -> [(Integer,(a,a))] trancl' r = foldl' into' mzero $ r ++ [(a1 + b1, (fst a2, snd b2)) | (a1, a2) <- r, (b1, b2) <- r, snd a2 == fst b2] trancl :: Eq a => [(Integer,(a,a))] -> [(Integer,(a,a))] trancl r = if trancl' r == r then r else trancl $ trancl' r {-TTEW-}