changeset 94:bcd4fe52a504

Rewrite monad definitions for delta/deltaM
author Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
date Mon, 19 Jan 2015 17:10:29 +0900
parents 8d92ed54a94f
children cf372fbcebd8
files agda/delta.agda agda/delta/monad.agda agda/deltaM.agda agda/laws.agda delta.hs
diffstat 5 files changed, 232 insertions(+), 207 deletions(-) [+]
line wrap: on
line diff
--- a/agda/delta.agda	Mon Jan 19 15:21:29 2015 +0900
+++ b/agda/delta.agda	Mon Jan 19 17:10:29 2015 +0900
@@ -39,30 +39,25 @@
 
 
 -- Monad (Category)
-eta : {l : Level} {A : Set l} -> A -> Delta A
-eta x = mono x
-
-bind : {l : Level} {A B : Set l} -> (Delta A) -> (A -> Delta B) -> Delta B
-bind (mono x)    f = f x
-bind (delta x d) f = delta (headDelta (f x)) (bind d (tailDelta ∙ f))
+delta-eta : {l : Level} {A : Set l} -> A -> Delta A
+delta-eta x = mono x
 
-mu : {l : Level} {A : Set l} -> Delta (Delta A) -> Delta A
-mu d = bind d id
+delta-bind : {l : Level} {A B : Set l} -> (Delta A) -> (A -> Delta B) -> Delta B
+delta-bind (mono x)    f = f x
+delta-bind (delta x d) f = delta (headDelta (f x)) (delta-bind d (tailDelta ∙ f))
 
-returnS : {l : Level} {A : Set l} -> A -> Delta A
-returnS x = mono x
+delta-mu : {l : Level} {A : Set l} -> Delta (Delta A) -> Delta A
+delta-mu d = delta-bind d id
 
-returnSS : {l : Level} {A : Set l} -> A -> A -> Delta A
-returnSS x y = deltaAppend (returnS x) (returnS y)
 
 
 -- Monad (Haskell)
-return : {l : Level} {A : Set l} -> A -> Delta A
-return = eta
+delta-return : {l : Level} {A : Set l} -> A -> Delta A
+delta-return = delta-eta
 
 _>>=_ : {l : Level} {A B : Set l} ->
         (x : Delta A) -> (f : A -> (Delta B)) -> (Delta B)
-(mono x) >>= f    = f x
+(mono x)    >>= f = f x
 (delta x d) >>= f = delta (headDelta (f x)) (d >>= (tailDelta ∙ f))
 
 
--- a/agda/delta/monad.agda	Mon Jan 19 15:21:29 2015 +0900
+++ b/agda/delta/monad.agda	Mon Jan 19 17:10:29 2015 +0900
@@ -15,36 +15,36 @@
 -- Monad-laws (Category)
 
 monad-law-1-5 : {l : Level} {A : Set l} -> (m : Nat) (n : Nat) -> (ds : Delta (Delta A)) ->
-  n-tail n (bind ds (n-tail m))  ≡ bind (n-tail n ds) (n-tail (m + n))
+  n-tail n (delta-bind ds (n-tail m))  ≡ delta-bind (n-tail n ds) (n-tail (m + n))
 monad-law-1-5 O O ds = refl
 monad-law-1-5 O (S n) (mono ds) = begin
-  n-tail (S n) (bind (mono ds) (n-tail O))     ≡⟨ refl ⟩
+  n-tail (S n) (delta-bind (mono ds) (n-tail O))     ≡⟨ refl ⟩
   n-tail (S n) ds                              ≡⟨ refl ⟩
-  bind (mono ds) (n-tail (S n))                ≡⟨ cong (\de -> bind de (n-tail (S n))) (sym (tail-delta-to-mono (S n) ds)) ⟩
-  bind (n-tail (S n) (mono ds)) (n-tail (S n)) ≡⟨ refl ⟩
-  bind (n-tail (S n) (mono ds)) (n-tail (O + S n))
+  delta-bind (mono ds) (n-tail (S n))                ≡⟨ cong (\de -> delta-bind de (n-tail (S n))) (sym (tail-delta-to-mono (S n) ds)) ⟩
+  delta-bind (n-tail (S n) (mono ds)) (n-tail (S n)) ≡⟨ refl ⟩
+  delta-bind (n-tail (S n) (mono ds)) (n-tail (O + S n))

 monad-law-1-5 O (S n) (delta d ds) = begin
-  n-tail (S n) (bind (delta d ds) (n-tail O))                         ≡⟨ refl ⟩
-  n-tail (S n) (delta (headDelta d) (bind ds tailDelta ))             ≡⟨ cong (\t -> t  (delta (headDelta d) (bind ds tailDelta ))) (sym (n-tail-plus n)) ⟩
-  ((n-tail n) ∙ tailDelta) (delta (headDelta d) (bind ds tailDelta )) ≡⟨ refl ⟩
-  (n-tail n) (bind ds tailDelta)                                      ≡⟨ monad-law-1-5 (S O) n ds ⟩
-  bind (n-tail n ds) (n-tail  (S n))                                  ≡⟨ refl ⟩
-  bind (((n-tail n) ∙ tailDelta) (delta d ds)) (n-tail  (S n))        ≡⟨ cong (\t -> bind (t (delta d ds)) (n-tail  (S n))) (n-tail-plus n) ⟩
-  bind (n-tail (S n) (delta d ds)) (n-tail  (S n))                    ≡⟨ refl ⟩
-  bind (n-tail (S n) (delta d ds)) (n-tail (O + S n))
+  n-tail (S n) (delta-bind (delta d ds) (n-tail O))                         ≡⟨ refl ⟩
+  n-tail (S n) (delta (headDelta d) (delta-bind ds tailDelta ))             ≡⟨ cong (\t -> t  (delta (headDelta d) (delta-bind ds tailDelta ))) (sym (n-tail-plus n)) ⟩
+  ((n-tail n) ∙ tailDelta) (delta (headDelta d) (delta-bind ds tailDelta )) ≡⟨ refl ⟩
+  (n-tail n) (delta-bind ds tailDelta)                                      ≡⟨ monad-law-1-5 (S O) n ds ⟩
+  delta-bind (n-tail n ds) (n-tail  (S n))                                  ≡⟨ refl ⟩
+  delta-bind (((n-tail n) ∙ tailDelta) (delta d ds)) (n-tail  (S n))        ≡⟨ cong (\t -> delta-bind (t (delta d ds)) (n-tail  (S n))) (n-tail-plus n) ⟩
+  delta-bind (n-tail (S n) (delta d ds)) (n-tail  (S n))                    ≡⟨ refl ⟩
+  delta-bind (n-tail (S n) (delta d ds)) (n-tail (O + S n))

 monad-law-1-5 (S m) n (mono (mono x)) = begin
-  n-tail n (bind (mono (mono x)) (n-tail (S m))) ≡⟨ refl ⟩
+  n-tail n (delta-bind (mono (mono x)) (n-tail (S m))) ≡⟨ refl ⟩
   n-tail n (n-tail (S m) (mono x))               ≡⟨ cong (\de -> n-tail n de) (tail-delta-to-mono (S m) x)⟩
   n-tail n (mono x)                              ≡⟨ tail-delta-to-mono n x ⟩
   mono x                                         ≡⟨ sym (tail-delta-to-mono (S m + n) x) ⟩
   (n-tail (S m + n)) (mono x)                    ≡⟨ refl ⟩
-  bind (mono (mono x)) (n-tail (S m + n))        ≡⟨ cong (\de -> bind de (n-tail (S m + n))) (sym (tail-delta-to-mono n (mono x))) ⟩
-  bind (n-tail n (mono (mono x))) (n-tail (S m + n))
+  delta-bind (mono (mono x)) (n-tail (S m + n))  ≡⟨ cong (\de -> delta-bind de (n-tail (S m + n))) (sym (tail-delta-to-mono n (mono x))) ⟩
+  delta-bind (n-tail n (mono (mono x))) (n-tail (S m + n))

 monad-law-1-5 (S m) n (mono (delta x ds)) = begin
-  n-tail n (bind (mono (delta x ds)) (n-tail (S m))) ≡⟨ refl ⟩
+  n-tail n (delta-bind (mono (delta x ds)) (n-tail (S m))) ≡⟨ refl ⟩
   n-tail n (n-tail (S m) (delta x ds))               ≡⟨ cong (\t -> n-tail n (t (delta x ds))) (sym (n-tail-plus m)) ⟩
   n-tail n (((n-tail m) ∙ tailDelta) (delta x ds))   ≡⟨ refl ⟩
   n-tail n ((n-tail m) ds)                           ≡⟨ cong (\t -> t ds) (n-tail-add {d = ds} n m)  ⟩
@@ -53,186 +53,186 @@
   ((n-tail (m + n)) ∙ tailDelta) (delta x ds)        ≡⟨ cong (\t -> t (delta x ds)) (n-tail-plus (m + n))⟩
   n-tail (S (m + n)) (delta x ds)                    ≡⟨ refl ⟩
   n-tail (S m + n) (delta x ds)                      ≡⟨ refl ⟩
-  bind (mono (delta x ds)) (n-tail (S m + n))        ≡⟨ cong (\de -> bind de (n-tail (S m + n))) (sym (tail-delta-to-mono n (delta x ds))) ⟩
-  bind (n-tail n (mono (delta x ds))) (n-tail (S m + n))
+  delta-bind (mono (delta x ds)) (n-tail (S m + n))        ≡⟨ cong (\de -> delta-bind de (n-tail (S m + n))) (sym (tail-delta-to-mono n (delta x ds))) ⟩
+  delta-bind (n-tail n (mono (delta x ds))) (n-tail (S m + n))

 monad-law-1-5 (S m) O (delta d ds) = begin
-  n-tail O (bind (delta d ds) (n-tail (S m)))                                 ≡⟨ refl ⟩
-  (bind (delta d ds) (n-tail (S m)))                                          ≡⟨ refl ⟩
-  delta (headDelta ((n-tail (S m)) d)) (bind ds (tailDelta ∙ (n-tail (S m)))) ≡⟨ refl ⟩
-  bind (delta d ds) (n-tail (S m))                                            ≡⟨ refl ⟩
-  bind (n-tail O (delta d ds)) (n-tail (S m))                                 ≡⟨ cong (\n -> bind (n-tail O (delta d ds)) (n-tail n)) (nat-add-right-zero (S m)) ⟩
-  bind (n-tail O (delta d ds)) (n-tail (S m + O))
+  n-tail O (delta-bind (delta d ds) (n-tail (S m)))                                 ≡⟨ refl ⟩
+  (delta-bind (delta d ds) (n-tail (S m)))                                          ≡⟨ refl ⟩
+  delta (headDelta ((n-tail (S m)) d)) (delta-bind ds (tailDelta ∙ (n-tail (S m)))) ≡⟨ refl ⟩
+  delta-bind (delta d ds) (n-tail (S m))                                            ≡⟨ refl ⟩
+  delta-bind (n-tail O (delta d ds)) (n-tail (S m))                                 ≡⟨ cong (\n -> delta-bind (n-tail O (delta d ds)) (n-tail n)) (nat-add-right-zero (S m)) ⟩
+  delta-bind (n-tail O (delta d ds)) (n-tail (S m + O))

 monad-law-1-5 (S m) (S n) (delta d ds) = begin
-  n-tail (S n) (bind (delta d ds) (n-tail (S m)))                                                         ≡⟨ cong (\t -> t ((bind (delta d ds) (n-tail (S m))))) (sym (n-tail-plus n)) ⟩
-  ((n-tail n) ∙ tailDelta) (bind (delta d ds) (n-tail (S m)))                                             ≡⟨ refl ⟩
-  ((n-tail n) ∙ tailDelta) (delta (headDelta ((n-tail (S m)) d)) (bind ds (tailDelta ∙  (n-tail (S m))))) ≡⟨ refl ⟩
-  (n-tail n) (bind ds (tailDelta ∙ (n-tail (S m))))                                                       ≡⟨ refl ⟩
-  (n-tail n) (bind ds (n-tail (S (S m))))                                                                 ≡⟨ monad-law-1-5 (S (S m)) n ds ⟩
-  bind ((n-tail n) ds) (n-tail (S (S (m + n))))                                                           ≡⟨ cong (\nm -> bind ((n-tail n) ds) (n-tail nm))  (sym (nat-right-increment (S m) n)) ⟩
-  bind ((n-tail n) ds) (n-tail (S m + S n))                                                               ≡⟨ refl ⟩
-  bind (((n-tail n) ∙ tailDelta) (delta d ds)) (n-tail (S m + S n))                                       ≡⟨ cong (\t -> bind (t (delta d ds)) (n-tail (S m + S n))) (n-tail-plus n) ⟩
-  bind (n-tail (S n) (delta d ds)) (n-tail (S m + S n))
+  n-tail (S n) (delta-bind (delta d ds) (n-tail (S m)))                                                         ≡⟨ cong (\t -> t ((delta-bind (delta d ds) (n-tail (S m))))) (sym (n-tail-plus n)) ⟩
+  ((n-tail n) ∙ tailDelta) (delta-bind (delta d ds) (n-tail (S m)))                                             ≡⟨ refl ⟩
+  ((n-tail n) ∙ tailDelta) (delta (headDelta ((n-tail (S m)) d)) (delta-bind ds (tailDelta ∙  (n-tail (S m))))) ≡⟨ refl ⟩
+  (n-tail n) (delta-bind ds (tailDelta ∙ (n-tail (S m))))                                                       ≡⟨ refl ⟩
+  (n-tail n) (delta-bind ds (n-tail (S (S m))))                                                                 ≡⟨ monad-law-1-5 (S (S m)) n ds ⟩
+  delta-bind ((n-tail n) ds) (n-tail (S (S (m + n))))                                                           ≡⟨ cong (\nm -> delta-bind ((n-tail n) ds) (n-tail nm))  (sym (nat-right-increment (S m) n)) ⟩
+  delta-bind ((n-tail n) ds) (n-tail (S m + S n))                                                               ≡⟨ refl ⟩
+  delta-bind (((n-tail n) ∙ tailDelta) (delta d ds)) (n-tail (S m + S n))                                       ≡⟨ cong (\t -> delta-bind (t (delta d ds)) (n-tail (S m + S n))) (n-tail-plus n) ⟩
+  delta-bind (n-tail (S n) (delta d ds)) (n-tail (S m + S n))

 
 monad-law-1-4 : {l : Level} {A : Set l} -> (m n : Nat) -> (dd : Delta (Delta A)) ->
-  headDelta ((n-tail n) (bind dd (n-tail m))) ≡ headDelta ((n-tail (m + n)) (headDelta (n-tail n dd)))
+  headDelta ((n-tail n) (delta-bind dd (n-tail m))) ≡ headDelta ((n-tail (m + n)) (headDelta (n-tail n dd)))
 monad-law-1-4 O O (mono dd) = refl
 monad-law-1-4 O O (delta dd dd₁) = refl
 monad-law-1-4 O (S n) (mono dd) = begin
-  headDelta (n-tail (S n) (bind (mono dd) (n-tail O)))          ≡⟨ refl ⟩
+  headDelta (n-tail (S n) (delta-bind (mono dd) (n-tail O)))    ≡⟨ refl ⟩
   headDelta (n-tail (S n) dd)                                   ≡⟨ refl ⟩
   headDelta (n-tail (S n) (headDelta (mono dd)))                ≡⟨ cong (\de -> headDelta (n-tail (S n) (headDelta de))) (sym (tail-delta-to-mono (S n) dd)) ⟩
   headDelta (n-tail (S n) (headDelta (n-tail (S n) (mono dd)))) ≡⟨ refl ⟩
   headDelta (n-tail (O + S n) (headDelta (n-tail (S n) (mono dd))))

 monad-law-1-4 O (S n) (delta d ds) = begin
-  headDelta (n-tail (S n) (bind (delta d ds) (n-tail O)))                        ≡⟨ refl ⟩
-  headDelta (n-tail (S n) (bind (delta d ds) id))                                ≡⟨ refl ⟩
-  headDelta (n-tail (S n) (delta (headDelta d) (bind ds tailDelta)))             ≡⟨ cong (\t -> headDelta (t (delta (headDelta d) (bind ds tailDelta)))) (sym (n-tail-plus n)) ⟩
-  headDelta (((n-tail n) ∙ tailDelta) (delta (headDelta d) (bind ds tailDelta))) ≡⟨ refl ⟩
-  headDelta (n-tail n (bind ds tailDelta))                                       ≡⟨ monad-law-1-4 (S O) n ds ⟩
-  headDelta (n-tail (S n) (headDelta (n-tail n ds)))                             ≡⟨ refl ⟩
-  headDelta (n-tail (S n) (headDelta (((n-tail n) ∙ tailDelta) (delta d ds))))   ≡⟨ cong (\t -> headDelta (n-tail (S n) (headDelta (t (delta d ds))))) (n-tail-plus n)  ⟩
-  headDelta (n-tail (S n) (headDelta (n-tail (S n) (delta d ds))))               ≡⟨ refl ⟩
+  headDelta (n-tail (S n) (delta-bind (delta d ds) (n-tail O)))                        ≡⟨ refl ⟩
+  headDelta (n-tail (S n) (delta-bind (delta d ds) id))                                ≡⟨ refl ⟩
+  headDelta (n-tail (S n) (delta (headDelta d) (delta-bind ds tailDelta)))             ≡⟨ cong (\t -> headDelta (t (delta (headDelta d) (delta-bind ds tailDelta)))) (sym (n-tail-plus n)) ⟩
+  headDelta (((n-tail n) ∙ tailDelta) (delta (headDelta d) (delta-bind ds tailDelta))) ≡⟨ refl ⟩
+  headDelta (n-tail n (delta-bind ds tailDelta))                                       ≡⟨ monad-law-1-4 (S O) n ds ⟩
+  headDelta (n-tail (S n) (headDelta (n-tail n ds)))                                   ≡⟨ refl ⟩
+  headDelta (n-tail (S n) (headDelta (((n-tail n) ∙ tailDelta) (delta d ds))))         ≡⟨ cong (\t -> headDelta (n-tail (S n) (headDelta (t (delta d ds))))) (n-tail-plus n)  ⟩
+  headDelta (n-tail (S n) (headDelta (n-tail (S n) (delta d ds))))                     ≡⟨ refl ⟩
   headDelta (n-tail (O + S n) (headDelta (n-tail (S n) (delta d ds))))

 monad-law-1-4 (S m) n (mono dd) = begin
-  headDelta (n-tail n (bind (mono dd) (n-tail (S m)))) ≡⟨ refl ⟩
-  headDelta (n-tail n ((n-tail (S m)) dd))             ≡⟨ cong (\t -> headDelta (t dd)) (n-tail-add {d = dd} n (S m)) ⟩
-  headDelta (n-tail (n + S m) dd)                      ≡⟨ cong (\n -> headDelta ((n-tail n) dd)) (nat-add-sym n (S m)) ⟩
-  headDelta (n-tail (S m + n) dd)                      ≡⟨ refl ⟩
-  headDelta (n-tail (S m + n) (headDelta (mono dd)))   ≡⟨ cong (\de -> headDelta (n-tail (S m + n) (headDelta de))) (sym (tail-delta-to-mono n dd)) ⟩
+  headDelta (n-tail n (delta-bind (mono dd) (n-tail (S m)))) ≡⟨ refl ⟩
+  headDelta (n-tail n ((n-tail (S m)) dd))                   ≡⟨ cong (\t -> headDelta (t dd)) (n-tail-add {d = dd} n (S m)) ⟩
+  headDelta (n-tail (n + S m) dd)                            ≡⟨ cong (\n -> headDelta ((n-tail n) dd)) (nat-add-sym n (S m)) ⟩
+  headDelta (n-tail (S m + n) dd)                            ≡⟨ refl ⟩
+  headDelta (n-tail (S m + n) (headDelta (mono dd)))         ≡⟨ cong (\de -> headDelta (n-tail (S m + n) (headDelta de))) (sym (tail-delta-to-mono n dd)) ⟩
   headDelta (n-tail (S m + n) (headDelta (n-tail n (mono dd))))

 monad-law-1-4 (S m) O (delta d ds) = begin
-  headDelta (n-tail O (bind (delta d ds) (n-tail (S m))))                                 ≡⟨ refl ⟩
-  headDelta (bind (delta d ds) (n-tail (S m)))                                            ≡⟨ refl ⟩
-  headDelta (delta (headDelta ((n-tail (S m) d))) (bind ds (tailDelta ∙ (n-tail (S m))))) ≡⟨ refl ⟩
+  headDelta (n-tail O (delta-bind (delta d ds) (n-tail (S m))))                                 ≡⟨ refl ⟩
+  headDelta (delta-bind (delta d ds) (n-tail (S m)))                                            ≡⟨ refl ⟩
+  headDelta (delta (headDelta ((n-tail (S m) d))) (delta-bind ds (tailDelta ∙ (n-tail (S m))))) ≡⟨ refl ⟩
   headDelta (n-tail (S m) d)                                                              ≡⟨ cong (\n -> headDelta ((n-tail n) d)) (nat-add-right-zero (S m)) ⟩
   headDelta (n-tail (S m + O) d)                                                          ≡⟨ refl ⟩
   headDelta (n-tail (S m + O) (headDelta (delta d ds)))                                   ≡⟨ refl ⟩
   headDelta (n-tail (S m + O) (headDelta (n-tail O (delta d ds))))

 monad-law-1-4 (S m) (S n) (delta d ds) = begin
-  headDelta (n-tail (S n) (bind (delta d ds) (n-tail (S m))))                                                          ≡⟨ refl ⟩
-  headDelta (n-tail (S n) (delta (headDelta ((n-tail (S m)) d)) (bind ds (tailDelta ∙ (n-tail (S m))))))               ≡⟨ cong (\t -> headDelta (t (delta (headDelta ((n-tail (S m)) d)) (bind ds (tailDelta ∙ (n-tail (S m))))))) (sym (n-tail-plus n)) ⟩
-  headDelta ((((n-tail n) ∙ tailDelta) (delta (headDelta ((n-tail (S m)) d)) (bind ds (tailDelta ∙ (n-tail (S m))))))) ≡⟨ refl ⟩
-  headDelta (n-tail n (bind ds (tailDelta ∙ (n-tail (S m)))))                                                          ≡⟨ refl ⟩
-  headDelta (n-tail n (bind ds  (n-tail (S (S m)))))                                                                   ≡⟨ monad-law-1-4 (S (S m)) n ds ⟩
+  headDelta (n-tail (S n) (delta-bind (delta d ds) (n-tail (S m))))                                                          ≡⟨ refl ⟩
+  headDelta (n-tail (S n) (delta (headDelta ((n-tail (S m)) d)) (delta-bind ds (tailDelta ∙ (n-tail (S m))))))               ≡⟨ cong (\t -> headDelta (t (delta (headDelta ((n-tail (S m)) d)) (delta-bind ds (tailDelta ∙ (n-tail (S m))))))) (sym (n-tail-plus n)) ⟩
+  headDelta ((((n-tail n) ∙ tailDelta) (delta (headDelta ((n-tail (S m)) d)) (delta-bind ds (tailDelta ∙ (n-tail (S m))))))) ≡⟨ refl ⟩
+  headDelta (n-tail n (delta-bind ds (tailDelta ∙ (n-tail (S m)))))                                                          ≡⟨ refl ⟩
+  headDelta (n-tail n (delta-bind ds  (n-tail (S (S m)))))                                                                   ≡⟨ monad-law-1-4 (S (S m)) n ds ⟩
   headDelta (n-tail ((S (S m) +  n)) (headDelta (n-tail n ds)))                                                        ≡⟨ cong (\nm -> headDelta ((n-tail nm) (headDelta (n-tail n ds)))) (sym (nat-right-increment (S m) n))  ⟩
   headDelta (n-tail (S m + S n) (headDelta (n-tail n ds)))                                                             ≡⟨ refl ⟩
   headDelta (n-tail (S m + S n) (headDelta (((n-tail n) ∙ tailDelta) (delta d ds))))                                   ≡⟨ cong (\t -> headDelta (n-tail (S m + S n) (headDelta (t (delta d ds))))) (n-tail-plus n) ⟩
   headDelta (n-tail (S m + S n) (headDelta (n-tail (S n) (delta d ds))))

 
-monad-law-1-2 : {l : Level} {A : Set l} -> (d : Delta (Delta A)) -> headDelta (mu d) ≡ (headDelta (headDelta d))
+monad-law-1-2 : {l : Level} {A : Set l} -> (d : Delta (Delta A)) -> headDelta (delta-mu d) ≡ (headDelta (headDelta d))
 monad-law-1-2 (mono _) = refl
 monad-law-1-2 (delta _ _) = refl
 
 monad-law-1-3 : {l : Level} {A : Set l} -> (n : Nat) -> (d : Delta (Delta (Delta A))) ->
-  bind (delta-fmap mu d) (n-tail n) ≡ bind (bind d (n-tail n)) (n-tail n)
+  delta-bind (delta-fmap delta-mu d) (n-tail n) ≡ delta-bind (delta-bind d (n-tail n)) (n-tail n)
 monad-law-1-3 O (mono d)     = refl
 monad-law-1-3 O (delta d ds) = begin
-  bind (delta-fmap mu (delta d ds)) (n-tail O)                               ≡⟨ refl ⟩
-  bind (delta (mu d) (delta-fmap mu ds)) (n-tail O)                          ≡⟨ refl ⟩
-  delta (headDelta (mu d)) (bind (delta-fmap mu ds) tailDelta)               ≡⟨ cong (\dx -> delta dx (bind (delta-fmap mu ds) tailDelta)) (monad-law-1-2 d) ⟩
-  delta (headDelta (headDelta d)) (bind (delta-fmap mu ds) tailDelta)        ≡⟨ cong (\dx -> delta (headDelta (headDelta d)) dx) (monad-law-1-3 (S O) ds) ⟩
-  delta (headDelta (headDelta d)) (bind (bind ds tailDelta) tailDelta) ≡⟨ refl ⟩
-  bind (delta (headDelta d) (bind ds tailDelta)) (n-tail O)            ≡⟨ refl ⟩
-  bind (bind (delta d ds) (n-tail O)) (n-tail O)
+  delta-bind (delta-fmap delta-mu (delta d ds)) (n-tail O)                               ≡⟨ refl ⟩
+  delta-bind (delta (delta-mu d) (delta-fmap delta-mu ds)) (n-tail O)                          ≡⟨ refl ⟩
+  delta (headDelta (delta-mu d)) (delta-bind (delta-fmap delta-mu ds) tailDelta)               ≡⟨ cong (\dx -> delta dx (delta-bind (delta-fmap delta-mu ds) tailDelta)) (monad-law-1-2 d) ⟩
+  delta (headDelta (headDelta d)) (delta-bind (delta-fmap delta-mu ds) tailDelta)        ≡⟨ cong (\dx -> delta (headDelta (headDelta d)) dx) (monad-law-1-3 (S O) ds) ⟩
+  delta (headDelta (headDelta d)) (delta-bind (delta-bind ds tailDelta) tailDelta) ≡⟨ refl ⟩
+  delta-bind (delta (headDelta d) (delta-bind ds tailDelta)) (n-tail O)            ≡⟨ refl ⟩
+  delta-bind (delta-bind (delta d ds) (n-tail O)) (n-tail O)

 monad-law-1-3 (S n) (mono (mono d)) = begin
-  bind (delta-fmap mu (mono (mono d))) (n-tail (S n)) ≡⟨ refl ⟩
-  bind (mono d) (n-tail (S n))                  ≡⟨ refl ⟩
+  delta-bind (delta-fmap delta-mu (mono (mono d))) (n-tail (S n)) ≡⟨ refl ⟩
+  delta-bind (mono d) (n-tail (S n))                  ≡⟨ refl ⟩
   (n-tail (S n)) d                              ≡⟨ refl ⟩
-  bind (mono d) (n-tail (S n))                  ≡⟨ cong (\t -> bind t (n-tail (S n))) (sym (tail-delta-to-mono (S n) d))⟩
-  bind (n-tail (S n) (mono d)) (n-tail (S n))   ≡⟨ refl ⟩
-  bind (n-tail (S n) (mono d)) (n-tail (S n))   ≡⟨ refl ⟩
-  bind (bind (mono (mono d)) (n-tail (S n))) (n-tail (S n))
+  delta-bind (mono d) (n-tail (S n))                  ≡⟨ cong (\t -> delta-bind t (n-tail (S n))) (sym (tail-delta-to-mono (S n) d))⟩
+  delta-bind (n-tail (S n) (mono d)) (n-tail (S n))   ≡⟨ refl ⟩
+  delta-bind (n-tail (S n) (mono d)) (n-tail (S n))   ≡⟨ refl ⟩
+  delta-bind (delta-bind (mono (mono d)) (n-tail (S n))) (n-tail (S n))

 monad-law-1-3 (S n) (mono (delta d ds)) = begin
-  bind (delta-fmap mu (mono (delta d ds))) (n-tail (S n))                ≡⟨ refl ⟩
-  bind (mono (mu (delta d ds))) (n-tail (S n))                     ≡⟨ refl ⟩
-  n-tail (S n) (mu (delta d ds))                                   ≡⟨ refl ⟩
-  n-tail (S n) (delta (headDelta d) (bind ds tailDelta))           ≡⟨ cong (\t -> t (delta (headDelta d) (bind ds tailDelta))) (sym (n-tail-plus n)) ⟩
-  (n-tail n ∙ tailDelta) (delta (headDelta d) (bind ds tailDelta)) ≡⟨ refl ⟩
-  n-tail n (bind ds tailDelta)                                     ≡⟨ monad-law-1-5 (S O) n ds ⟩
-  bind (n-tail n ds) (n-tail (S n))                                ≡⟨ refl ⟩
-  bind (((n-tail n) ∙ tailDelta) (delta d ds)) (n-tail (S n))      ≡⟨ cong (\t -> (bind (t (delta d ds)) (n-tail (S n))))  (n-tail-plus n) ⟩
-  bind (n-tail (S n) (delta d ds)) (n-tail (S n))                  ≡⟨ refl ⟩
-  bind (bind (mono (delta d ds)) (n-tail (S n))) (n-tail (S n))
+  delta-bind (delta-fmap delta-mu (mono (delta d ds))) (n-tail (S n))                ≡⟨ refl ⟩
+  delta-bind (mono (delta-mu (delta d ds))) (n-tail (S n))                     ≡⟨ refl ⟩
+  n-tail (S n) (delta-mu (delta d ds))                                   ≡⟨ refl ⟩
+  n-tail (S n) (delta (headDelta d) (delta-bind ds tailDelta))           ≡⟨ cong (\t -> t (delta (headDelta d) (delta-bind ds tailDelta))) (sym (n-tail-plus n)) ⟩
+  (n-tail n ∙ tailDelta) (delta (headDelta d) (delta-bind ds tailDelta)) ≡⟨ refl ⟩
+  n-tail n (delta-bind ds tailDelta)                                     ≡⟨ monad-law-1-5 (S O) n ds ⟩
+  delta-bind (n-tail n ds) (n-tail (S n))                                ≡⟨ refl ⟩
+  delta-bind (((n-tail n) ∙ tailDelta) (delta d ds)) (n-tail (S n))      ≡⟨ cong (\t -> (delta-bind (t (delta d ds)) (n-tail (S n))))  (n-tail-plus n) ⟩
+  delta-bind (n-tail (S n) (delta d ds)) (n-tail (S n))                  ≡⟨ refl ⟩
+  delta-bind (delta-bind (mono (delta d ds)) (n-tail (S n))) (n-tail (S n))

 monad-law-1-3 (S n) (delta (mono d) ds) = begin
-  bind (delta-fmap mu (delta (mono d) ds)) (n-tail (S n)) ≡⟨ refl ⟩
-  bind (delta (mu (mono d)) (delta-fmap mu ds)) (n-tail (S n)) ≡⟨ refl ⟩
-  bind (delta d (delta-fmap mu ds)) (n-tail (S n)) ≡⟨ refl ⟩
-  delta (headDelta ((n-tail (S n)) d)) (bind (delta-fmap mu ds) (tailDelta ∙ (n-tail (S n)))) ≡⟨ refl ⟩
-  delta (headDelta ((n-tail (S n)) d)) (bind (delta-fmap mu ds) (n-tail (S (S n)))) ≡⟨ cong (\de -> delta (headDelta ((n-tail (S n)) d)) de) (monad-law-1-3 (S (S n)) ds) ⟩
-  delta (headDelta ((n-tail (S n)) d)) (bind (bind ds (n-tail (S (S n)))) (n-tail (S (S n)))) ≡⟨ refl ⟩
-  delta (headDelta ((n-tail (S n)) d)) (bind (bind ds (tailDelta ∙ (n-tail (S n))))  (n-tail (S (S n)))) ≡⟨ refl ⟩
-  delta (headDelta ((n-tail (S n)) d)) (bind (bind ds (tailDelta ∙ (n-tail (S n)))) (tailDelta ∙  (n-tail (S n)))) ≡⟨ refl ⟩
-  delta (headDelta ((n-tail (S n)) (headDelta (mono d)))) (bind (bind ds (tailDelta ∙ (n-tail (S n)))) (tailDelta ∙  (n-tail (S n)))) ≡⟨ cong (\de -> delta (headDelta ((n-tail (S n)) (headDelta de))) (bind (bind ds (tailDelta ∙ (n-tail (S n)))) (tailDelta ∙  (n-tail (S n))))) (sym (tail-delta-to-mono (S n) d)) ⟩
-  delta (headDelta ((n-tail (S n)) (headDelta ((n-tail (S n)) (mono d))))) (bind (bind ds (tailDelta ∙ (n-tail (S n)))) (tailDelta ∙  (n-tail (S n)))) ≡⟨ refl ⟩
-  bind (delta (headDelta ((n-tail (S n)) (mono d))) (bind ds (tailDelta ∙ (n-tail (S n))))) (n-tail (S n)) ≡⟨ refl ⟩
-  bind (bind (delta (mono d) ds) (n-tail (S n))) (n-tail (S n))
+  delta-bind (delta-fmap delta-mu (delta (mono d) ds)) (n-tail (S n)) ≡⟨ refl ⟩
+  delta-bind (delta (delta-mu (mono d)) (delta-fmap delta-mu ds)) (n-tail (S n)) ≡⟨ refl ⟩
+  delta-bind (delta d (delta-fmap delta-mu ds)) (n-tail (S n)) ≡⟨ refl ⟩
+  delta (headDelta ((n-tail (S n)) d)) (delta-bind (delta-fmap delta-mu ds) (tailDelta ∙ (n-tail (S n)))) ≡⟨ refl ⟩
+  delta (headDelta ((n-tail (S n)) d)) (delta-bind (delta-fmap delta-mu ds) (n-tail (S (S n)))) ≡⟨ cong (\de -> delta (headDelta ((n-tail (S n)) d)) de) (monad-law-1-3 (S (S n)) ds) ⟩
+  delta (headDelta ((n-tail (S n)) d)) (delta-bind (delta-bind ds (n-tail (S (S n)))) (n-tail (S (S n)))) ≡⟨ refl ⟩
+  delta (headDelta ((n-tail (S n)) d)) (delta-bind (delta-bind ds (tailDelta ∙ (n-tail (S n))))  (n-tail (S (S n)))) ≡⟨ refl ⟩
+  delta (headDelta ((n-tail (S n)) d)) (delta-bind (delta-bind ds (tailDelta ∙ (n-tail (S n)))) (tailDelta ∙  (n-tail (S n)))) ≡⟨ refl ⟩
+  delta (headDelta ((n-tail (S n)) (headDelta (mono d)))) (delta-bind (delta-bind ds (tailDelta ∙ (n-tail (S n)))) (tailDelta ∙  (n-tail (S n)))) ≡⟨ cong (\de -> delta (headDelta ((n-tail (S n)) (headDelta de))) (delta-bind (delta-bind ds (tailDelta ∙ (n-tail (S n)))) (tailDelta ∙  (n-tail (S n))))) (sym (tail-delta-to-mono (S n) d)) ⟩
+  delta (headDelta ((n-tail (S n)) (headDelta ((n-tail (S n)) (mono d))))) (delta-bind (delta-bind ds (tailDelta ∙ (n-tail (S n)))) (tailDelta ∙  (n-tail (S n)))) ≡⟨ refl ⟩
+  delta-bind (delta (headDelta ((n-tail (S n)) (mono d))) (delta-bind ds (tailDelta ∙ (n-tail (S n))))) (n-tail (S n)) ≡⟨ refl ⟩
+  delta-bind (delta-bind (delta (mono d) ds) (n-tail (S n))) (n-tail (S n))

 monad-law-1-3 (S n) (delta (delta d dd) ds) = begin
-  bind (delta-fmap mu (delta (delta d dd) ds)) (n-tail (S n)) ≡⟨ refl ⟩
-  bind (delta (mu (delta d dd)) (delta-fmap mu ds)) (n-tail (S n)) ≡⟨ refl ⟩
-  delta (headDelta ((n-tail (S n)) (mu (delta d dd)))) (bind (delta-fmap mu ds) (tailDelta ∙ (n-tail (S n)))) ≡⟨ refl ⟩
-  delta (headDelta ((n-tail (S n)) (delta (headDelta d) (bind dd tailDelta)))) (bind (delta-fmap mu ds) (tailDelta ∙ (n-tail (S n)))) ≡⟨ cong (\t -> delta (headDelta (t (delta (headDelta d) (bind dd tailDelta)))) (bind (delta-fmap mu ds) (tailDelta ∙ (n-tail (S n)))))(sym (n-tail-plus n)) ⟩
-  delta (headDelta (((n-tail n) ∙ tailDelta) (delta (headDelta d) (bind dd tailDelta)))) (bind (delta-fmap mu ds) (tailDelta ∙ (n-tail (S n)))) ≡⟨ refl ⟩
-  delta (headDelta ((n-tail n) (bind dd tailDelta))) (bind (delta-fmap mu ds) (tailDelta ∙ (n-tail (S n)))) ≡⟨ refl ⟩
-  delta (headDelta ((n-tail n) (bind dd tailDelta))) (bind (delta-fmap mu ds) (n-tail (S (S n)))) ≡⟨ cong (\de -> delta (headDelta ((n-tail n) (bind dd tailDelta))) de) (monad-law-1-3 (S (S n)) ds) ⟩
-  delta (headDelta ((n-tail n) (bind dd tailDelta))) (bind (bind  ds (n-tail (S (S n))))  (n-tail (S (S n)))) ≡⟨ cong (\de -> delta de ( (bind (bind  ds (n-tail (S (S n))))  (n-tail (S (S n)))))) (monad-law-1-4 (S O) n dd) ⟩
-  delta (headDelta ((n-tail (S n)) (headDelta (n-tail n dd)))) (bind (bind  ds (n-tail (S (S n))))  (n-tail (S (S n)))) ≡⟨ refl ⟩
-  delta (headDelta ((n-tail (S n)) (headDelta (n-tail n dd)))) (bind (bind  ds (n-tail (S (S n)))) (tailDelta ∙ (n-tail (S n)))) ≡⟨ refl ⟩
-  delta (headDelta ((n-tail (S n)) (headDelta (n-tail n dd)))) (bind (bind  ds (tailDelta ∙ (n-tail (S n)))) (tailDelta ∙ (n-tail (S n)))) ≡⟨ refl ⟩
-  delta (headDelta ((n-tail (S n)) (headDelta (((n-tail n) ∙ tailDelta) (delta d dd))))) (bind (bind  ds (tailDelta ∙ (n-tail (S n)))) (tailDelta ∙ (n-tail (S n)))) ≡⟨ cong (\t -> delta (headDelta ((n-tail (S n)) (headDelta (t (delta d dd))))) (bind (bind  ds (tailDelta ∙ (n-tail (S n)))) (tailDelta ∙ (n-tail (S n))))) (n-tail-plus n) ⟩
-  delta (headDelta ((n-tail (S n)) (headDelta ((n-tail (S n)) (delta d dd))))) (bind (bind  ds (tailDelta ∙ (n-tail (S n)))) (tailDelta ∙ (n-tail (S n)))) ≡⟨ refl ⟩
-  bind (delta (headDelta ((n-tail (S n)) (delta d dd))) (bind  ds (tailDelta ∙ (n-tail (S n))))) (n-tail (S n)) ≡⟨ refl ⟩
-  bind (bind (delta (delta d dd) ds) (n-tail (S n))) (n-tail (S n))
+  delta-bind (delta-fmap delta-mu (delta (delta d dd) ds)) (n-tail (S n)) ≡⟨ refl ⟩
+  delta-bind (delta (delta-mu (delta d dd)) (delta-fmap delta-mu ds)) (n-tail (S n)) ≡⟨ refl ⟩
+  delta (headDelta ((n-tail (S n)) (delta-mu (delta d dd)))) (delta-bind (delta-fmap delta-mu ds) (tailDelta ∙ (n-tail (S n)))) ≡⟨ refl ⟩
+  delta (headDelta ((n-tail (S n)) (delta (headDelta d) (delta-bind dd tailDelta)))) (delta-bind (delta-fmap delta-mu ds) (tailDelta ∙ (n-tail (S n)))) ≡⟨ cong (\t -> delta (headDelta (t (delta (headDelta d) (delta-bind dd tailDelta)))) (delta-bind (delta-fmap delta-mu ds) (tailDelta ∙ (n-tail (S n)))))(sym (n-tail-plus n)) ⟩
+  delta (headDelta (((n-tail n) ∙ tailDelta) (delta (headDelta d) (delta-bind dd tailDelta)))) (delta-bind (delta-fmap delta-mu ds) (tailDelta ∙ (n-tail (S n)))) ≡⟨ refl ⟩
+  delta (headDelta ((n-tail n) (delta-bind dd tailDelta))) (delta-bind (delta-fmap delta-mu ds) (tailDelta ∙ (n-tail (S n)))) ≡⟨ refl ⟩
+  delta (headDelta ((n-tail n) (delta-bind dd tailDelta))) (delta-bind (delta-fmap delta-mu ds) (n-tail (S (S n)))) ≡⟨ cong (\de -> delta (headDelta ((n-tail n) (delta-bind dd tailDelta))) de) (monad-law-1-3 (S (S n)) ds) ⟩
+  delta (headDelta ((n-tail n) (delta-bind dd tailDelta))) (delta-bind (delta-bind  ds (n-tail (S (S n))))  (n-tail (S (S n)))) ≡⟨ cong (\de -> delta de ( (delta-bind (delta-bind  ds (n-tail (S (S n))))  (n-tail (S (S n)))))) (monad-law-1-4 (S O) n dd) ⟩
+  delta (headDelta ((n-tail (S n)) (headDelta (n-tail n dd)))) (delta-bind (delta-bind  ds (n-tail (S (S n))))  (n-tail (S (S n)))) ≡⟨ refl ⟩
+  delta (headDelta ((n-tail (S n)) (headDelta (n-tail n dd)))) (delta-bind (delta-bind  ds (n-tail (S (S n)))) (tailDelta ∙ (n-tail (S n)))) ≡⟨ refl ⟩
+  delta (headDelta ((n-tail (S n)) (headDelta (n-tail n dd)))) (delta-bind (delta-bind  ds (tailDelta ∙ (n-tail (S n)))) (tailDelta ∙ (n-tail (S n)))) ≡⟨ refl ⟩
+  delta (headDelta ((n-tail (S n)) (headDelta (((n-tail n) ∙ tailDelta) (delta d dd))))) (delta-bind (delta-bind  ds (tailDelta ∙ (n-tail (S n)))) (tailDelta ∙ (n-tail (S n)))) ≡⟨ cong (\t -> delta (headDelta ((n-tail (S n)) (headDelta (t (delta d dd))))) (delta-bind (delta-bind  ds (tailDelta ∙ (n-tail (S n)))) (tailDelta ∙ (n-tail (S n))))) (n-tail-plus n) ⟩
+  delta (headDelta ((n-tail (S n)) (headDelta ((n-tail (S n)) (delta d dd))))) (delta-bind (delta-bind  ds (tailDelta ∙ (n-tail (S n)))) (tailDelta ∙ (n-tail (S n)))) ≡⟨ refl ⟩
+  delta-bind (delta (headDelta ((n-tail (S n)) (delta d dd))) (delta-bind  ds (tailDelta ∙ (n-tail (S n))))) (n-tail (S n)) ≡⟨ refl ⟩
+  delta-bind (delta-bind (delta (delta d dd) ds) (n-tail (S n))) (n-tail (S n))

 
 
 -- monad-law-1 : join . delta-fmap join = join . join
-monad-law-1 : {l : Level} {A : Set l} -> (d : Delta (Delta (Delta A))) -> ((mu ∙ (delta-fmap mu)) d) ≡ ((mu ∙ mu) d)
+monad-law-1 : {l : Level} {A : Set l} -> (d : Delta (Delta (Delta A))) -> ((delta-mu ∙ (delta-fmap delta-mu)) d) ≡ ((delta-mu ∙ delta-mu) d)
 monad-law-1 (mono d)    = refl
 monad-law-1 (delta x d) = begin
-  (mu ∙ delta-fmap mu) (delta x d)                                          ≡⟨ refl ⟩
-  mu (delta-fmap mu (delta x d))                                            ≡⟨ refl ⟩
-  mu (delta (mu x) (delta-fmap mu d))                                       ≡⟨ refl ⟩
-  delta (headDelta (mu x)) (bind (delta-fmap mu d) tailDelta)               ≡⟨ cong (\x -> delta x (bind (delta-fmap mu d) tailDelta)) (monad-law-1-2 x) ⟩
-  delta (headDelta (headDelta x)) (bind (delta-fmap mu d) tailDelta)        ≡⟨ cong (\d -> delta (headDelta (headDelta x)) d) (monad-law-1-3 (S O) d) ⟩
-  delta (headDelta (headDelta x)) (bind (bind d tailDelta) tailDelta) ≡⟨ refl ⟩
-  mu (delta (headDelta x) (bind d tailDelta))                         ≡⟨ refl ⟩
-  mu (mu (delta x d))                                                 ≡⟨ refl ⟩
-  (mu ∙ mu) (delta x d)
+  (delta-mu ∙ delta-fmap delta-mu) (delta x d)                                          ≡⟨ refl ⟩
+  delta-mu (delta-fmap delta-mu (delta x d))                                            ≡⟨ refl ⟩
+  delta-mu (delta (delta-mu x) (delta-fmap delta-mu d))                                       ≡⟨ refl ⟩
+  delta (headDelta (delta-mu x)) (delta-bind (delta-fmap delta-mu d) tailDelta)               ≡⟨ cong (\x -> delta x (delta-bind (delta-fmap delta-mu d) tailDelta)) (monad-law-1-2 x) ⟩
+  delta (headDelta (headDelta x)) (delta-bind (delta-fmap delta-mu d) tailDelta)        ≡⟨ cong (\d -> delta (headDelta (headDelta x)) d) (monad-law-1-3 (S O) d) ⟩
+  delta (headDelta (headDelta x)) (delta-bind (delta-bind d tailDelta) tailDelta) ≡⟨ refl ⟩
+  delta-mu (delta (headDelta x) (delta-bind d tailDelta))                         ≡⟨ refl ⟩
+  delta-mu (delta-mu (delta x d))                                                 ≡⟨ refl ⟩
+  (delta-mu ∙ delta-mu) (delta x d)

 
 
-monad-law-2-1 : {l : Level} {A : Set l} -> (n : Nat) -> (d : Delta A) -> (bind (delta-fmap eta d) (n-tail n)) ≡ d
+monad-law-2-1 : {l : Level} {A : Set l} -> (n : Nat) -> (d : Delta A) -> (delta-bind (delta-fmap delta-eta d) (n-tail n)) ≡ d
 monad-law-2-1 O (mono x)    = refl
 monad-law-2-1 O (delta x d) = begin
-  bind (delta-fmap eta (delta x d)) (n-tail O)                  ≡⟨ refl ⟩
-  bind (delta (eta x) (delta-fmap eta d)) id                    ≡⟨ refl ⟩
-  delta (headDelta (eta x)) (bind (delta-fmap eta d) tailDelta) ≡⟨ refl ⟩
-  delta x (bind (delta-fmap eta d) tailDelta)                   ≡⟨ cong (\de -> delta x de) (monad-law-2-1 (S O) d) ⟩
+  delta-bind (delta-fmap delta-eta (delta x d)) (n-tail O)                  ≡⟨ refl ⟩
+  delta-bind (delta (delta-eta x) (delta-fmap delta-eta d)) id                    ≡⟨ refl ⟩
+  delta (headDelta (delta-eta x)) (delta-bind (delta-fmap delta-eta d) tailDelta) ≡⟨ refl ⟩
+  delta x (delta-bind (delta-fmap delta-eta d) tailDelta)                   ≡⟨ cong (\de -> delta x de) (monad-law-2-1 (S O) d) ⟩
   delta x d                                               ∎
 monad-law-2-1 (S n) (mono x) = begin
-  bind (delta-fmap eta (mono x)) (n-tail (S n)) ≡⟨ refl ⟩
-  bind (mono (mono x)) (n-tail (S n))     ≡⟨ refl ⟩
+  delta-bind (delta-fmap delta-eta (mono x)) (n-tail (S n)) ≡⟨ refl ⟩
+  delta-bind (mono (mono x)) (n-tail (S n))     ≡⟨ refl ⟩
   n-tail (S n) (mono x)                   ≡⟨ tail-delta-to-mono (S n) x ⟩
   mono x                                  ∎
 monad-law-2-1 (S n) (delta x d) = begin
-  bind (delta-fmap eta (delta x d)) (n-tail (S n))                                                   ≡⟨ refl ⟩
-  bind (delta (eta x) (delta-fmap eta d)) (n-tail (S n))                                             ≡⟨ refl ⟩
-  delta (headDelta ((n-tail (S n) (eta x)))) (bind (delta-fmap eta d) (tailDelta ∙  (n-tail (S n)))) ≡⟨ refl ⟩
-  delta (headDelta ((n-tail (S n) (eta x)))) (bind (delta-fmap eta d) (n-tail (S (S n))))            ≡⟨ cong (\de -> delta (headDelta (de)) (bind (delta-fmap eta d) (n-tail (S (S n))))) (tail-delta-to-mono (S n) x) ⟩
-  delta (headDelta (eta x)) (bind (delta-fmap eta d) (n-tail (S (S n))))                             ≡⟨ refl ⟩
-  delta x (bind (delta-fmap eta d) (n-tail (S (S n))))                                               ≡⟨ cong (\d -> delta x d) (monad-law-2-1 (S (S n)) d) ⟩
+  delta-bind (delta-fmap delta-eta (delta x d)) (n-tail (S n))                                                   ≡⟨ refl ⟩
+  delta-bind (delta (delta-eta x) (delta-fmap delta-eta d)) (n-tail (S n))                                             ≡⟨ refl ⟩
+  delta (headDelta ((n-tail (S n) (delta-eta x)))) (delta-bind (delta-fmap delta-eta d) (tailDelta ∙  (n-tail (S n)))) ≡⟨ refl ⟩
+  delta (headDelta ((n-tail (S n) (delta-eta x)))) (delta-bind (delta-fmap delta-eta d) (n-tail (S (S n))))            ≡⟨ cong (\de -> delta (headDelta (de)) (delta-bind (delta-fmap delta-eta d) (n-tail (S (S n))))) (tail-delta-to-mono (S n) x) ⟩
+  delta (headDelta (delta-eta x)) (delta-bind (delta-fmap delta-eta d) (n-tail (S (S n))))                             ≡⟨ refl ⟩
+  delta x (delta-bind (delta-fmap delta-eta d) (n-tail (S (S n))))                                               ≡⟨ cong (\d -> delta x d) (monad-law-2-1 (S (S n)) d) ⟩
   delta x d

 
@@ -240,91 +240,93 @@
 -- monad-law-2 : join . delta-fmap return = join . return = id
 -- monad-law-2 join . delta-fmap return = join . return
 monad-law-2 : {l : Level} {A : Set l} -> (d : Delta A) ->
-  (mu ∙ delta-fmap eta) d ≡ (mu ∙ eta) d
+  (delta-mu ∙ delta-fmap delta-eta) d ≡ (delta-mu ∙ delta-eta) d
 monad-law-2 (mono x)    = refl
 monad-law-2 (delta x d) = begin
-  (mu ∙ delta-fmap eta) (delta x d)                              ≡⟨ refl ⟩
-  mu (delta-fmap eta (delta x d))                                ≡⟨ refl ⟩
-  mu (delta (mono x) (delta-fmap eta d))                         ≡⟨ refl ⟩
-  delta (headDelta (mono x)) (bind (delta-fmap eta d) tailDelta) ≡⟨ refl ⟩
-  delta x (bind (delta-fmap eta d) tailDelta)                    ≡⟨ cong (\d -> delta x d) (monad-law-2-1 (S O) d) ⟩
+  (delta-mu ∙ delta-fmap delta-eta) (delta x d)                              ≡⟨ refl ⟩
+  delta-mu (delta-fmap delta-eta (delta x d))                                ≡⟨ refl ⟩
+  delta-mu (delta (mono x) (delta-fmap delta-eta d))                         ≡⟨ refl ⟩
+  delta (headDelta (mono x)) (delta-bind (delta-fmap delta-eta d) tailDelta) ≡⟨ refl ⟩
+  delta x (delta-bind (delta-fmap delta-eta d) tailDelta)                    ≡⟨ cong (\d -> delta x d) (monad-law-2-1 (S O) d) ⟩
   (delta x d)                                              ≡⟨ refl ⟩
-  mu (mono (delta x d))                                    ≡⟨ refl ⟩
-  mu (eta (delta x d))                                     ≡⟨ refl ⟩
-  (mu ∙ eta) (delta x d)
+  delta-mu (mono (delta x d))                                    ≡⟨ refl ⟩
+  delta-mu (delta-eta (delta x d))                                     ≡⟨ refl ⟩
+  (delta-mu ∙ delta-eta) (delta x d)

 
 
 -- monad-law-2' :  join . return = id
-monad-law-2' : {l : Level} {A : Set l} -> (d : Delta A) -> (mu ∙ eta) d ≡ id d
+monad-law-2' : {l : Level} {A : Set l} -> (d : Delta A) -> (delta-mu ∙ delta-eta) d ≡ id d
 monad-law-2' d = refl
 
 
 -- monad-law-3 : return . f = delta-fmap f . return
-monad-law-3 : {l : Level} {A B : Set l} (f : A -> B) (x : A) -> (eta ∙ f) x ≡ (delta-fmap f ∙ eta) x
+monad-law-3 : {l : Level} {A B : Set l} (f : A -> B) (x : A) -> (delta-eta ∙ f) x ≡ (delta-fmap f ∙ delta-eta) x
 monad-law-3 f x = refl
 
 
 monad-law-4-1 : {l ll : Level} {A : Set l} {B : Set ll} -> (n : Nat) -> (f : A -> B) -> (ds : Delta (Delta A)) ->
-  bind (delta-fmap (delta-fmap f) ds) (n-tail n) ≡ delta-fmap f (bind ds (n-tail n))
+  delta-bind (delta-fmap (delta-fmap f) ds) (n-tail n) ≡ delta-fmap f (delta-bind ds (n-tail n))
 monad-law-4-1 O f (mono d)     = refl
 monad-law-4-1 O f (delta d ds) = begin
-  bind (delta-fmap (delta-fmap f) (delta d ds)) (n-tail O)                     ≡⟨ refl ⟩
-  bind (delta (delta-fmap f d) (delta-fmap (delta-fmap f) ds)) (n-tail O)            ≡⟨ refl ⟩
-  delta (headDelta (delta-fmap f d)) (bind (delta-fmap (delta-fmap f) ds) tailDelta) ≡⟨ cong (\de -> delta de (bind (delta-fmap (delta-fmap f) ds) tailDelta)) (head-delta-natural-transformation f d) ⟩
-  delta (f (headDelta d))      (bind (delta-fmap (delta-fmap f) ds) tailDelta) ≡⟨ cong (\de -> delta (f (headDelta d)) de) (monad-law-4-1 (S O) f ds) ⟩
-  delta (f (headDelta d))      (delta-fmap f (bind ds tailDelta))        ≡⟨ refl ⟩
-  delta-fmap f (delta (headDelta d) (bind ds tailDelta))                 ≡⟨ refl ⟩
-  delta-fmap f (bind (delta d ds) (n-tail O))                            ∎
+  delta-bind (delta-fmap (delta-fmap f) (delta d ds)) (n-tail O)                     ≡⟨ refl ⟩
+  delta-bind (delta (delta-fmap f d) (delta-fmap (delta-fmap f) ds)) (n-tail O)            ≡⟨ refl ⟩
+  delta (headDelta (delta-fmap f d)) (delta-bind (delta-fmap (delta-fmap f) ds) tailDelta) ≡⟨ cong (\de -> delta de (delta-bind (delta-fmap (delta-fmap f) ds) tailDelta)) (head-delta-natural-transformation f d) ⟩
+  delta (f (headDelta d))      (delta-bind (delta-fmap (delta-fmap f) ds) tailDelta) ≡⟨ cong (\de -> delta (f (headDelta d)) de) (monad-law-4-1 (S O) f ds) ⟩
+  delta (f (headDelta d))      (delta-fmap f (delta-bind ds tailDelta))        ≡⟨ refl ⟩
+  delta-fmap f (delta (headDelta d) (delta-bind ds tailDelta))                 ≡⟨ refl ⟩
+  delta-fmap f (delta-bind (delta d ds) (n-tail O))                            ∎
 monad-law-4-1 (S n) f (mono d) = begin
-  bind (delta-fmap (delta-fmap f) (mono d)) (n-tail (S n)) ≡⟨ refl ⟩
-  bind (mono (delta-fmap f d)) (n-tail (S n))        ≡⟨ refl ⟩
+  delta-bind (delta-fmap (delta-fmap f) (mono d)) (n-tail (S n)) ≡⟨ refl ⟩
+  delta-bind (mono (delta-fmap f d)) (n-tail (S n))        ≡⟨ refl ⟩
   n-tail (S n) (delta-fmap f d)                      ≡⟨ n-tail-natural-transformation (S n) f d ⟩
   delta-fmap f (n-tail (S n) d)                      ≡⟨ refl ⟩
-  delta-fmap f (bind (mono d) (n-tail (S n)))
+  delta-fmap f (delta-bind (mono d) (n-tail (S n)))

 monad-law-4-1 (S n) f (delta d ds) = begin
-  bind (delta-fmap (delta-fmap f) (delta d ds)) (n-tail (S n)) ≡⟨ refl ⟩
-  delta (headDelta (n-tail (S n) (delta-fmap f d))) (bind (delta-fmap (delta-fmap f) ds) (tailDelta ∙ (n-tail (S n))))  ≡⟨ refl ⟩
-  delta (headDelta (n-tail (S n) (delta-fmap f d))) (bind (delta-fmap (delta-fmap f) ds) (n-tail (S (S n))))            ≡⟨ cong (\de ->   delta (headDelta de) (bind (delta-fmap (delta-fmap f) ds) (n-tail (S (S n))))) (n-tail-natural-transformation (S n) f d) ⟩
-  delta (headDelta (delta-fmap f ((n-tail (S n) d)))) (bind (delta-fmap (delta-fmap f) ds) (n-tail (S (S n))))          ≡⟨ cong (\de -> delta de (bind (delta-fmap (delta-fmap f) ds) (n-tail (S (S n))))) (head-delta-natural-transformation f (n-tail (S n) d)) ⟩
-  delta (f (headDelta (n-tail (S n) d))) (bind (delta-fmap (delta-fmap f) ds) (n-tail (S (S n))))                 ≡⟨ cong (\de -> delta (f (headDelta (n-tail (S n) d))) de) (monad-law-4-1 (S (S n)) f ds) ⟩
-  delta (f (headDelta (n-tail (S n) d))) (delta-fmap f (bind ds (n-tail (S (S n)))))                        ≡⟨ refl ⟩
-  delta-fmap f (delta (headDelta (n-tail (S n) d)) (bind ds (n-tail (S (S n)))))                            ≡⟨ refl ⟩
-  delta-fmap f (delta (headDelta (n-tail (S n) d)) (bind ds (tailDelta ∙ (n-tail (S n)))))                  ≡⟨ refl ⟩
-  delta-fmap f (bind (delta d ds) (n-tail (S n)))                                                           ∎
+  delta-bind (delta-fmap (delta-fmap f) (delta d ds)) (n-tail (S n)) ≡⟨ refl ⟩
+  delta (headDelta (n-tail (S n) (delta-fmap f d))) (delta-bind (delta-fmap (delta-fmap f) ds) (tailDelta ∙ (n-tail (S n))))  ≡⟨ refl ⟩
+  delta (headDelta (n-tail (S n) (delta-fmap f d))) (delta-bind (delta-fmap (delta-fmap f) ds) (n-tail (S (S n))))            ≡⟨ cong (\de ->   delta (headDelta de) (delta-bind (delta-fmap (delta-fmap f) ds) (n-tail (S (S n))))) (n-tail-natural-transformation (S n) f d) ⟩
+  delta (headDelta (delta-fmap f ((n-tail (S n) d)))) (delta-bind (delta-fmap (delta-fmap f) ds) (n-tail (S (S n))))          ≡⟨ cong (\de -> delta de (delta-bind (delta-fmap (delta-fmap f) ds) (n-tail (S (S n))))) (head-delta-natural-transformation f (n-tail (S n) d)) ⟩
+  delta (f (headDelta (n-tail (S n) d))) (delta-bind (delta-fmap (delta-fmap f) ds) (n-tail (S (S n))))                 ≡⟨ cong (\de -> delta (f (headDelta (n-tail (S n) d))) de) (monad-law-4-1 (S (S n)) f ds) ⟩
+  delta (f (headDelta (n-tail (S n) d))) (delta-fmap f (delta-bind ds (n-tail (S (S n)))))                        ≡⟨ refl ⟩
+  delta-fmap f (delta (headDelta (n-tail (S n) d)) (delta-bind ds (n-tail (S (S n)))))                            ≡⟨ refl ⟩
+  delta-fmap f (delta (headDelta (n-tail (S n) d)) (delta-bind ds (tailDelta ∙ (n-tail (S n)))))                  ≡⟨ refl ⟩
+  delta-fmap f (delta-bind (delta d ds) (n-tail (S n)))                                                           ∎
 
 
 -- monad-law-4 : join . delta-fmap (delta-fmap f) = delta-fmap f . join
 monad-law-4 : {l : Level} {A B : Set l} (f : A -> B) (d : Delta (Delta A)) ->
-              (mu ∙ delta-fmap (delta-fmap f)) d ≡ (delta-fmap f ∙ mu) d
+              (delta-mu ∙ delta-fmap (delta-fmap f)) d ≡ (delta-fmap f ∙ delta-mu) d
 monad-law-4 f (mono d)     = refl
 monad-law-4 f (delta (mono x) ds) = begin
-  (mu ∙ delta-fmap (delta-fmap f)) (delta (mono x) ds)                           ≡⟨ refl ⟩
-  mu ( delta-fmap (delta-fmap f) (delta (mono x) ds))                            ≡⟨ refl ⟩
-  mu (delta (mono (f x)) (delta-fmap (delta-fmap f) ds))                         ≡⟨ refl ⟩
-  delta (headDelta (mono (f x))) (bind (delta-fmap (delta-fmap f) ds) tailDelta) ≡⟨ refl ⟩
-  delta (f x) (bind (delta-fmap (delta-fmap f) ds) tailDelta)                    ≡⟨ cong (\de -> delta (f x) de) (monad-law-4-1 (S O) f ds) ⟩
-  delta (f x) (delta-fmap f (bind ds tailDelta))                           ≡⟨ refl ⟩
-  delta-fmap f (delta x (bind ds tailDelta))                               ≡⟨ refl ⟩
-  delta-fmap f (delta (headDelta (mono x)) (bind ds tailDelta))            ≡⟨ refl ⟩
-  delta-fmap f (mu (delta (mono x) ds))                                    ≡⟨ refl ⟩
-  (delta-fmap f ∙ mu) (delta (mono x) ds)                                  ∎
+  (delta-mu ∙ delta-fmap (delta-fmap f)) (delta (mono x) ds)                           ≡⟨ refl ⟩
+  delta-mu ( delta-fmap (delta-fmap f) (delta (mono x) ds))                            ≡⟨ refl ⟩
+  delta-mu (delta (mono (f x)) (delta-fmap (delta-fmap f) ds))                         ≡⟨ refl ⟩
+  delta (headDelta (mono (f x))) (delta-bind (delta-fmap (delta-fmap f) ds) tailDelta) ≡⟨ refl ⟩
+  delta (f x) (delta-bind (delta-fmap (delta-fmap f) ds) tailDelta)                    ≡⟨ cong (\de -> delta (f x) de) (monad-law-4-1 (S O) f ds) ⟩
+  delta (f x) (delta-fmap f (delta-bind ds tailDelta))                           ≡⟨ refl ⟩
+  delta-fmap f (delta x (delta-bind ds tailDelta))                               ≡⟨ refl ⟩
+  delta-fmap f (delta (headDelta (mono x)) (delta-bind ds tailDelta))            ≡⟨ refl ⟩
+  delta-fmap f (delta-mu (delta (mono x) ds))                                    ≡⟨ refl ⟩
+  (delta-fmap f ∙ delta-mu) (delta (mono x) ds)                                  ∎
 monad-law-4 f (delta (delta x d) ds) = begin
-  (mu ∙ delta-fmap (delta-fmap f)) (delta (delta x d) ds)                                     ≡⟨ refl ⟩
-  mu (delta-fmap (delta-fmap f) (delta (delta x d) ds))                                       ≡⟨ refl ⟩
-  mu  (delta (delta (f x) (delta-fmap f d)) (delta-fmap (delta-fmap f) ds))                         ≡⟨ refl ⟩
-  delta (headDelta (delta (f x) (delta-fmap f d)))  (bind (delta-fmap (delta-fmap f) ds) tailDelta) ≡⟨ refl ⟩
-  delta (f x)  (bind (delta-fmap (delta-fmap f) ds) tailDelta)                                ≡⟨ cong (\de -> delta (f x) de) (monad-law-4-1 (S O) f ds) ⟩
-  delta (f x) (delta-fmap f (bind  ds tailDelta))                                       ≡⟨ refl ⟩
-  delta-fmap f (delta x (bind  ds tailDelta))                                           ≡⟨ refl ⟩
-  delta-fmap f (delta (headDelta (delta x d)) (bind  ds tailDelta))                     ≡⟨ refl ⟩
-  delta-fmap f (mu (delta (delta x d) ds))                                              ≡⟨ refl ⟩
-  (delta-fmap f ∙ mu) (delta (delta x d) ds) ∎
+  (delta-mu ∙ delta-fmap (delta-fmap f)) (delta (delta x d) ds)                                     ≡⟨ refl ⟩
+  delta-mu (delta-fmap (delta-fmap f) (delta (delta x d) ds))                                       ≡⟨ refl ⟩
+  delta-mu  (delta (delta (f x) (delta-fmap f d)) (delta-fmap (delta-fmap f) ds))                         ≡⟨ refl ⟩
+  delta (headDelta (delta (f x) (delta-fmap f d)))  (delta-bind (delta-fmap (delta-fmap f) ds) tailDelta) ≡⟨ refl ⟩
+  delta (f x)  (delta-bind (delta-fmap (delta-fmap f) ds) tailDelta)                                ≡⟨ cong (\de -> delta (f x) de) (monad-law-4-1 (S O) f ds) ⟩
+  delta (f x) (delta-fmap f (delta-bind  ds tailDelta))                                       ≡⟨ refl ⟩
+  delta-fmap f (delta x (delta-bind  ds tailDelta))                                           ≡⟨ refl ⟩
+  delta-fmap f (delta (headDelta (delta x d)) (delta-bind  ds tailDelta))                     ≡⟨ refl ⟩
+  delta-fmap f (delta-mu (delta (delta x d) ds))                                              ≡⟨ refl ⟩
+  (delta-fmap f ∙ delta-mu) (delta (delta x d) ds) ∎
 
 delta-is-monad : {l : Level} {A : Set l} -> Monad {l} {A} Delta delta-is-functor
-delta-is-monad = record { mu = mu;
-                          eta = eta;
+delta-is-monad = record { eta    = delta-eta;
+                          mu     = delta-mu;
+                          return = delta-eta;
+                          bind   = delta-bind;
                           association-law = monad-law-1;
                           left-unity-law  = monad-law-2;
                           right-unity-law = monad-law-2' }
--- a/agda/deltaM.agda	Mon Jan 19 15:21:29 2015 +0900
+++ b/agda/deltaM.agda	Mon Jan 19 17:10:29 2015 +0900
@@ -1,5 +1,6 @@
 open import Level
 
+open import basic
 open import delta
 open import delta.functor
 open import nat
@@ -55,6 +56,8 @@
 checkOut {l} {A} {M} {functorM} {monadM} (S n) (deltaM (delta _ d)) = checkOut {l} {A} {M} {functorM} {monadM} n (deltaM d)
 
 
+
+-- functor definitions
 open Functor
 deltaM-fmap : {l : Level} {A B : Set l}
               {M : {l' : Level} -> Set l' -> Set l'}
@@ -62,3 +65,25 @@
               {monadM : {l' : Level} {A : Set l'} -> Monad {l'} {A} M functorM}
               -> (A -> B) -> DeltaM M {functorM} {monadM} A -> DeltaM M {functorM} {monadM} B
 deltaM-fmap {l} {A} {B} {M} {functorM} f (deltaM d) = deltaM (fmap delta-is-functor (fmap functorM f) d)
+
+-- monad definitions
+open Monad
+deltaM-eta : {l : Level} {A B : Set l} {M : {l' : Level} -> Set l' -> Set l'}
+                                        {functorM : {l' : Level} -> Functor {l'} M}
+                                        {monadM   : {l' : Level} {A : Set l'} -> Monad {l'} {A} M functorM}
+            -> A -> (DeltaM M {functorM} {monadM} A)
+deltaM-eta {_} {A} {_} {_} {_} {monadM} x = deltaM (mono (eta {_} {A} monadM x))
+
+deltaM-bind : {l : Level} {A B : Set l} {M : {l' : Level} -> Set l' -> Set l'} 
+                                        {functorM : {l' : Level} -> Functor {l'} M}
+                                        {monadM   : {l' : Level} {A : Set l'} -> Monad {l'} {A} M functorM}
+            -> (DeltaM M {functorM} {monadM} A) -> (A -> DeltaM M {functorM} {monadM} B) -> DeltaM M {functorM} {monadM} B
+deltaM-bind {l} {A} {B} {M} {functorM} {monadM} (deltaM (mono x))    f = deltaM (mono (bind {l} {A} monadM x (headDeltaM ∙ f)))
+deltaM-bind {l} {A} {B} {M} {functorM} {monadM} (deltaM (delta x d)) f = appendDeltaM (deltaM (mono (bind {l} {A} monadM x (headDeltaM ∙ f))))
+                                                                                      (deltaM-bind (deltaM d) (tailDeltaM ∙ f))
+
+deltaM-mu : {l : Level} {A B : Set l} {M : {l' : Level} -> Set l' -> Set l'}
+                                        {functorM : {l' : Level} -> Functor {l'} M}
+                                        {monadM   : {l' : Level} {A : Set l'} -> Monad {l'} {A} M functorM}
+            -> (DeltaM M {functorM} {monadM} (DeltaM M {functorM} {monadM} A)) -> DeltaM M {functorM} {monadM} A
+deltaM-mu d = deltaM-bind d id
\ No newline at end of file
--- a/agda/laws.agda	Mon Jan 19 15:21:29 2015 +0900
+++ b/agda/laws.agda	Mon Jan 19 17:10:29 2015 +0900
@@ -32,12 +32,15 @@
                          (M : {ll : Level} -> Set ll -> Set ll)
                          (functorM : Functor M)
                          : Set (suc l)  where
-  field
-    mu  : {A : Set l} -> M (M A) -> M A
-    eta : {A : Set l} -> A -> M A
-  field
+  field -- category
+    mu  :  {A : Set l} -> M (M A) -> M A
+    eta :  {A : Set l} -> A -> M A
+  field -- haskell
+    return : {A : Set l} -> A -> M A
+    bind   : {A B : Set l} -> M A -> (A -> (M B)) -> M B
+  field -- category laws
     association-law : (x : (M (M (M A)))) -> (mu ∙ (fmap functorM mu)) x ≡ (mu ∙ mu) x
     left-unity-law  : (x : M A) -> (mu  ∙ (fmap functorM eta)) x ≡ id x
     right-unity-law : (x : M A) -> id x ≡ (mu ∙ eta) x
 
-open Monad
\ No newline at end of file
+open Monad
--- a/delta.hs	Mon Jan 19 15:21:29 2015 +0900
+++ b/delta.hs	Mon Jan 19 17:10:29 2015 +0900
@@ -128,7 +128,7 @@
 instance (Monad m) => Monad (DeltaM m) where
     return x                   = DeltaM $ Mono $ return x
     (DeltaM (Mono x))    >>= f = DeltaM $ Mono $ (x >>= headDeltaM . f)
-    (DeltaM (Delta x d)) >>= f = appendDeltaM ((DeltaM $ Mono x) >>= f)
+    (DeltaM (Delta x d)) >>= f = appendDeltaM (DeltaM $ Mono $ (x >>= (headDeltaM . f)))
                                               ((DeltaM d) >>= tailDeltaM . f)