Mercurial > hg > Papers > 2015 > atton-thesis
annotate src/deltaM_definition.hs @ 49:ba7f0b5454ab
Add description for DeltaM definition
author | Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp> |
---|---|
date | Sun, 15 Feb 2015 14:07:07 +0900 |
parents | |
children |
rev | line source |
---|---|
49
ba7f0b5454ab
Add description for DeltaM definition
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1 data DeltaM m a = DeltaM (Delta (m a)) deriving (Show) |
ba7f0b5454ab
Add description for DeltaM definition
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
2 |
ba7f0b5454ab
Add description for DeltaM definition
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
3 -- DeltaM utils |
ba7f0b5454ab
Add description for DeltaM definition
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
4 |
ba7f0b5454ab
Add description for DeltaM definition
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
5 unDeltaM :: DeltaM m a -> Delta (m a) |
ba7f0b5454ab
Add description for DeltaM definition
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
6 unDeltaM (DeltaM d) = d |
ba7f0b5454ab
Add description for DeltaM definition
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
7 |
ba7f0b5454ab
Add description for DeltaM definition
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
8 headDeltaM :: DeltaM m a -> m a |
ba7f0b5454ab
Add description for DeltaM definition
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
9 headDeltaM (DeltaM d) = headDelta d |
ba7f0b5454ab
Add description for DeltaM definition
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
10 |
ba7f0b5454ab
Add description for DeltaM definition
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
11 tailDeltaM :: DeltaM m a -> DeltaM m a |
ba7f0b5454ab
Add description for DeltaM definition
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
12 tailDeltaM (DeltaM d) = DeltaM $ tailDelta d |
ba7f0b5454ab
Add description for DeltaM definition
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
13 |
ba7f0b5454ab
Add description for DeltaM definition
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
14 -- DeltaM instance definitions |
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 mu :: (Functor m, Monad m) => DeltaM m (DeltaM m a) -> DeltaM m a |
ba7f0b5454ab
Add description for DeltaM definition
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
17 mu d@(DeltaM (Mono _)) = |
ba7f0b5454ab
Add description for DeltaM definition
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
18 DeltaM (Mono ((>>= id) (fmap headDeltaM (headDeltaM d)))) |
ba7f0b5454ab
Add description for DeltaM definition
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
19 mu d@(DeltaM (Delta _ _)) = |
ba7f0b5454ab
Add description for DeltaM definition
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
20 DeltaM (Delta ((>>= id) (fmap headDeltaM (headDeltaM d))) |
ba7f0b5454ab
Add description for DeltaM definition
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
21 (unDeltaM (mu (fmap tailDeltaM (tailDeltaM d))))) |
ba7f0b5454ab
Add description for DeltaM definition
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
22 |
ba7f0b5454ab
Add description for DeltaM definition
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
23 instance (Functor m, Monad m) => Monad (DeltaM m) where |
ba7f0b5454ab
Add description for DeltaM definition
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
24 return x = DeltaM (Mono (return x)) |
ba7f0b5454ab
Add description for DeltaM definition
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
25 d >>= f = mu (fmap f d) |