### changeset 85:a1723b3ea997

Mini refactors
author Yasutaka Higa Mon, 05 Jan 2015 13:53:21 +0900 8c7bd8bf8092 5c083ddd73ed delta.hs 1 files changed, 8 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
```--- a/delta.hs	Sun Jan 04 17:32:01 2015 +0900
+++ b/delta.hs	Mon Jan 05 13:53:21 2015 +0900
@@ -2,7 +2,7 @@
import Data.Numbers.Primes -- \$ cabal install primes

--- delta definition
+-- Delta definition

data Delta a = Mono a | Delta a (Delta a) deriving Show

@@ -86,7 +86,9 @@
sortedValueR = replicate (length \$ filter (== maximumValue) xs) maximumValue
remainValue  = filter (/= maximumValue) xs

--- DeltaM Definition (Delta with Monad)
+
+
+-- DeltaM definition (Delta with Monad)

data DeltaM m a = DeltaM (Delta (m a)) deriving (Show)

@@ -141,8 +143,7 @@
return x

dmap :: (m a -> b) -> DeltaM m a -> Delta b
-dmap f (DeltaM (Mono mx))   = (Mono \$ f mx)
-dmap f (DeltaM (Delta x d)) = Delta (f x) (dmap f (DeltaM d))
+dmap f (DeltaM d) = fmap f d

-- example : prime filter
@@ -150,8 +151,8 @@
--         : dmap runWriter \$ primeCountM 30          -- run all version

generatorM :: Int -> DeltaWithLog [Int]
-generatorM x = let intList = returnW [1..x] in
-                             DeltaM \$ deltaFromList \$  [intList, intList]
+generatorM x = let intList = [1..x] in
+                             DeltaM \$ deltaFromList \$ fmap returnW \$ replicate 2 intList

primeFilterM :: [Int] -> DeltaWithLog [Int]
primeFilterM xs = let primeList    = filter isPrime xs
@@ -161,7 +162,7 @@