diff options
Diffstat (limited to 'difflist.hs')
-rw-r--r-- | difflist.hs | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/difflist.hs b/difflist.hs new file mode 100644 index 0000000..f206351 --- /dev/null +++ b/difflist.hs @@ -0,0 +1,27 @@ +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] |