annotate src/delta_example.hs @ 42:4cc65012412f

Add proofs of functor-laws on delta
author Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
date Fri, 13 Feb 2015 17:13:23 +0900
parents 324111203070
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
9
324111203070 Add example used delta
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1 module Example.Delta where
324111203070 Add example used delta
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
2
324111203070 Add example used delta
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
3 import Data.Numbers.Primes
324111203070 Add example used delta
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
4 import Delta
324111203070 Add example used delta
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
5
324111203070 Add example used delta
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
6 generator :: Int -> Delta [Int]
324111203070 Add example used delta
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
7 generator x = let intList = [1..x] in
324111203070 Add example used delta
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
8 return intList
324111203070 Add example used delta
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
9
324111203070 Add example used delta
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
10 numberFilter :: [Int] -> Delta [Int]
324111203070 Add example used delta
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
11 numberFilter xs = let primeList = filter isPrime xs
324111203070 Add example used delta
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
12 evenList = filter even xs in
324111203070 Add example used delta
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
13 Delta evenList (Mono primeList)
324111203070 Add example used delta
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
14
324111203070 Add example used delta
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
15 count :: [Int] -> Delta Int
324111203070 Add example used delta
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
16 count xs = let primeCount = length xs in
324111203070 Add example used delta
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
17 return primeCount
324111203070 Add example used delta
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
18
324111203070 Add example used delta
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
19 numberCount :: Int -> Delta Int
324111203070 Add example used delta
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
20 numberCount x = generator x >>= numberFilter >>= count
324111203070 Add example used delta
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
21