import Control.Monad.Writer newtype DiffList a = DiffList { getDiffList :: [a] -> [a] } toDiffList :: [a] -> DiffList a toDiffList xs = DiffList (xs++) fromDiffList :: DiffList a -> [a] fromDiffList (DiffList f) = f [] instance Monoid (DiffList a) where mempty = DiffList (\xs -> [] ++ xs) (DiffList f) `mappend` (DiffList g) = DiffList (\xs -> f (g xs)) diffCountDown :: Int -> Writer (DiffList String) () diffCountDown 0 = do tell (toDiffList ["0"]) diffCountDown x = do diffCountDown (x-1) tell (toDiffList [show x]) normCountDown :: Int -> Writer [String] () normCountDown 0 = do tell ["0"] normCountDown x = do normCountDown (x-1) tell [show x]