annotate src/deltaM_example.hs @ 57:5f0e13923cfd

Fixes
author Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
date Mon, 16 Feb 2015 16:24:42 +0900
parents 37a832dff044
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
49
ba7f0b5454ab Add description for DeltaM definition
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1 type DeltaLog = Writer [String]
ba7f0b5454ab Add description for DeltaM definition
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
2 type DeltaWithLog = DeltaM DeltaLog
ba7f0b5454ab Add description for DeltaM definition
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
3
ba7f0b5454ab Add description for DeltaM definition
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
4 returnW :: (Show a) => a -> DeltaLog a
50
37a832dff044 Add DeltaM example
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents: 49
diff changeset
5 returnW x = do tell ([show x])
49
ba7f0b5454ab Add description for DeltaM definition
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
6 return x
ba7f0b5454ab Add description for DeltaM definition
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
7
50
37a832dff044 Add DeltaM example
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents: 49
diff changeset
8 deltaAppend :: Delta a -> Delta a -> Delta a
37a832dff044 Add DeltaM example
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents: 49
diff changeset
9 deltaAppend (Mono x) d = Delta x d
37a832dff044 Add DeltaM example
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents: 49
diff changeset
10 deltaAppend (Delta x d) ds = Delta x (deltaAppend d ds)
49
ba7f0b5454ab Add description for DeltaM definition
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
11
50
37a832dff044 Add DeltaM example
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents: 49
diff changeset
12 deltaFromList :: [a] -> Delta a
37a832dff044 Add DeltaM example
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents: 49
diff changeset
13 deltaFromList = (foldl1 deltaAppend) . (fmap return)
49
ba7f0b5454ab Add description for DeltaM definition
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
14
ba7f0b5454ab Add description for DeltaM definition
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
15
ba7f0b5454ab Add description for DeltaM definition
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
16
ba7f0b5454ab Add description for DeltaM definition
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
17 generatorM :: Int -> DeltaWithLog [Int]
ba7f0b5454ab Add description for DeltaM definition
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
18 generatorM x = let intList = [1..x] in
50
37a832dff044 Add DeltaM example
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents: 49
diff changeset
19 DeltaM (deltaFromList (fmap returnW (replicate 2 intList)))
49
ba7f0b5454ab Add description for DeltaM definition
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
20
ba7f0b5454ab Add description for DeltaM definition
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
21 numberFilterM :: [Int] -> DeltaWithLog [Int]
ba7f0b5454ab Add description for DeltaM definition
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
22 numberFilterM xs = let primeList = filter isPrime xs
ba7f0b5454ab Add description for DeltaM definition
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
23 evenList = filter even xs in
50
37a832dff044 Add DeltaM example
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents: 49
diff changeset
24 DeltaM (deltaFromList (fmap returnW [primeList, evenList]))
49
ba7f0b5454ab Add description for DeltaM definition
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
25
ba7f0b5454ab Add description for DeltaM definition
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
26
ba7f0b5454ab Add description for DeltaM definition
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
27 countM :: [Int] -> DeltaWithLog Int
ba7f0b5454ab Add description for DeltaM definition
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
28 countM xs = let numberCount = length xs in
50
37a832dff044 Add DeltaM example
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents: 49
diff changeset
29 DeltaM (deltaFromList (fmap returnW (replicate 2 numberCount)))
49
ba7f0b5454ab Add description for DeltaM definition
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
30
ba7f0b5454ab Add description for DeltaM definition
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
31 numberCountM :: Int -> DeltaWithLog Int
ba7f0b5454ab Add description for DeltaM definition
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
32 numberCountM x = generatorM x >>= numberFilterM >>= countM