diff options
author | Joe Zhao <ztuowen@gmail.com> | 2014-08-08 09:20:42 +0800 |
---|---|---|
committer | Joe Zhao <ztuowen@gmail.com> | 2014-08-08 09:20:42 +0800 |
commit | 423693811904a6038a1a7532700726799e05fade (patch) | |
tree | f84fe7407251dd244e11c205b6e4353bdb66d9d3 /difflist.hs | |
parent | bc88e3464180e781e7ad2d552de0c8e496448d2e (diff) | |
download | haskbox-old-423693811904a6038a1a7532700726799e05fade.tar.gz haskbox-old-423693811904a6038a1a7532700726799e05fade.tar.bz2 haskbox-old-423693811904a6038a1a7532700726799e05fade.zip |
add difflist
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] |