blob: f2063518d24aaaa0d8b840e5d8fe74f752e95e5c (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
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]
|