changeset 105:e6499a50ccbd

Retrying prove monad-laws for delta
author Yasutaka Higa Tue, 27 Jan 2015 17:49:25 +0900 ebd0d6e2772c 2779a09e1526 agda/delta.agda agda/delta/functor.agda agda/delta/monad.agda 3 files changed, 148 insertions(+), 339 deletions(-) [+]
line wrap: on
line diff
```--- a/agda/delta.agda	Mon Jan 26 23:00:05 2015 +0900
+++ b/agda/delta.agda	Tue Jan 27 17:49:25 2015 +0900
@@ -1,7 +1,6 @@
open import list
open import basic
open import nat
-open import revision
open import laws

open import Level
@@ -10,42 +9,47 @@

module delta where

-data Delta {l : Level} (A : Set l) : (Rev -> (Set l)) where
-  mono    : A -> Delta A init
-  delta   : {v : Rev} -> A -> Delta A v -> Delta A (commit v)
+data Delta {l : Level} (A : Set l) : (Nat -> (Set l)) where
+  mono    : A -> Delta A (S O)
+  delta   : {n : Nat} -> A -> Delta A (S n) -> Delta A (S (S n))

-deltaAppend : {l : Level} {A : Set l} {n m : Rev} -> Delta A n -> Delta A m -> Delta A (merge n m)
+deltaAppend : {l : Level} {A : Set l} {n m : Nat} -> Delta A (S n) -> Delta A (S m) -> Delta A ((S n) + (S m))
deltaAppend (mono x) d     = delta x d
deltaAppend (delta x d) ds = delta x (deltaAppend d ds)

-headDelta : {l : Level} {A : Set l} {n : Rev} -> Delta A n -> A
+headDelta : {l : Level} {A : Set l} {n : Nat} -> Delta A (S n) -> A
headDelta (mono x)    = x
headDelta (delta x _) = x

-tailDelta : {l : Level} {A : Set l} {n : Rev} -> Delta A (commit n) -> Delta A n
+tailDelta : {l : Level} {A : Set l} {n : Nat} -> Delta A (S (S n)) -> Delta A (S n)
tailDelta (delta _ d) = d

-- Functor
-delta-fmap : {l : Level} {A B : Set l} {n : Rev} -> (A -> B) -> (Delta A n) -> (Delta B n)
+delta-fmap : {l : Level} {A B : Set l} {n : Nat} -> (A -> B) -> (Delta A (S n)) -> (Delta B (S n))
delta-fmap f (mono x)    = mono  (f x)
delta-fmap f (delta x d) = delta (f x) (delta-fmap f d)

-- Monad (Category)
-delta-eta : {l : Level} {A : Set l} {v : Rev} -> A -> Delta A v
-delta-eta {v = init} x     = mono x
-delta-eta {v = commit v} x = delta x (delta-eta {v = v} x)
+delta-eta : {l : Level} {A : Set l} {n : Nat} -> A -> Delta A (S n)
+delta-eta {n = O}     x = mono x
+delta-eta {n = (S n)} x = delta x (delta-eta {n = n} x)
+
+
+

-delta-bind : {l : Level} {A B : Set l} {n : Rev} -> (Delta A n) -> (A -> Delta B n) -> Delta B n
-delta-bind (mono x) f    = f x
-delta-bind (delta x d) f = delta (headDelta (f x)) (tailDelta (f x))
+delta-mu : {l : Level} {A : Set l} {n : Nat} -> (Delta (Delta A (S n)) (S n)) -> Delta A (S n)
+delta-mu (mono x)    = x
+delta-mu (delta x d) = delta (headDelta x) (delta-mu (delta-fmap tailDelta d))

-delta-mu : {l : Level} {A : Set l} {n : Rev} -> (Delta (Delta A n) n) -> Delta A n
-delta-mu d = delta-bind d id
+delta-bind : {l : Level} {A B : Set l} {n : Nat} -> (Delta A (S n)) -> (A -> Delta B (S n)) -> Delta B (S n)
+delta-bind d f = delta-mu (delta-fmap f d)

+--delta-bind (mono x) f    = f x
+--delta-bind (delta x d) f = delta (headDelta (f x)) (tailDelta (f x))

{-```
```--- a/agda/delta/functor.agda	Mon Jan 26 23:00:05 2015 +0900
+++ b/agda/delta/functor.agda	Tue Jan 27 17:49:25 2015 +0900
@@ -1,32 +1,43 @@
open import Level
open import Relation.Binary.PropositionalEquality

-
open import basic
open import delta
open import laws
open import nat
-open import revision
-
-

module delta.functor where

-- Functor-laws

-- Functor-law-1 : T(id) = id'
-functor-law-1 :  {l : Level} {A : Set l} {n : Rev} ->  (d : Delta A n) -> (delta-fmap id) d ≡ id d
+functor-law-1 :  {l : Level} {A : Set l} {n : Nat} ->  (d : Delta A (S n)) -> (delta-fmap id) d ≡ id d
functor-law-1 (mono x)    = refl
functor-law-1 (delta x d) = cong (delta x) (functor-law-1 d)

-- Functor-law-2 : T(f . g) = T(f) . T(g)
-functor-law-2 : {l : Level} {n : Rev} {A B C : Set l} ->
-                (f : B -> C) -> (g : A -> B) -> (d : Delta A n) ->
+functor-law-2 : {l : Level} {n : Nat} {A B C : Set l} ->
+                (f : B -> C) -> (g : A -> B) -> (d : Delta A (S n)) ->
(delta-fmap (f ∙ g)) d ≡ ((delta-fmap f) ∙ (delta-fmap g)) d
functor-law-2 f g (mono x)    = refl
functor-law-2 f g (delta x d) = cong (delta (f (g x))) (functor-law-2 f g d)

-delta-is-functor : {l : Level} {n : Rev} -> Functor {l} (\A -> Delta A n)
+
+
+delta-is-functor : {l : Level} {n : Nat} -> Functor {l} (\A -> Delta A (S n))
delta-is-functor = record {  fmap = delta-fmap ;
preserve-id = functor-law-1;
covariant  = \f g -> functor-law-2 g f}
+
+
+open ≡-Reasoning
+delta-fmap-equiv : {l : Level} {A B : Set l} {n : Nat}
+                   (f g : A -> B) (eq : f ≡ g) (d : Delta A (S n)) ->
+                 delta-fmap f d ≡ delta-fmap g d
+delta-fmap-equiv f g eq (mono x) = begin
+  mono (f x) ≡⟨ cong (\h -> (mono (h x))) eq ⟩
+  mono (g x) ∎
+delta-fmap-equiv f g eq (delta x d) = begin
+  delta (f x) (delta-fmap f d) ≡⟨ cong (\h -> (delta (h x) (delta-fmap f d))) eq ⟩
+  delta (g x) (delta-fmap f d) ≡⟨ cong (\fx -> (delta (g x) fx)) (delta-fmap-equiv f g eq d) ⟩
+  delta (g x) (delta-fmap g d)   ∎```
```--- a/agda/delta/monad.agda	Mon Jan 26 23:00:05 2015 +0900
+++ b/agda/delta/monad.agda	Tue Jan 27 17:49:25 2015 +0900
@@ -3,7 +3,6 @@
open import delta.functor
open import nat
open import laws
-open import revision

open import Level
@@ -12,335 +11,130 @@

module delta.monad where

+delta-eta-is-nt : {l : Level} {A B : Set l} -> {n : Nat}
+                  (f : A -> B) -> (x : A) -> (delta-eta {n = n} ∙ f) x ≡ delta-fmap f (delta-eta x)
+delta-eta-is-nt {n = O}   f x = refl
+delta-eta-is-nt {n = S O} f x = refl
+delta-eta-is-nt {n = S n} f x = begin
+  (delta-eta ∙ f) x                        ≡⟨ refl ⟩
+  delta-eta (f x)                          ≡⟨ refl ⟩
+  delta (f x) (delta-eta (f x))            ≡⟨ cong (\de -> delta (f x) de) (delta-eta-is-nt f x) ⟩
+  delta (f x) (delta-fmap f (delta-eta x)) ≡⟨ refl ⟩
+  delta-fmap f (delta x (delta-eta x))     ≡⟨ refl ⟩
+  delta-fmap f (delta-eta x)               ∎
+
+delta-mu-is-nt : {l : Level} {A B : Set l} {n : Nat} -> (f : A -> B) -> (d : Delta (Delta A (S n)) (S n))
+               -> delta-mu (delta-fmap (delta-fmap f) d) ≡ delta-fmap f (delta-mu d)
+delta-mu-is-nt f d = {!!}
+
+hoge : {l : Level} {A : Set l} {n : Nat} -> (ds : Delta (Delta A (S (S n))) (S (S n))) ->
+  (tailDelta {n = n} ∙ delta-mu {n = (S n)}) ds
+  ≡
+  (((delta-mu {n = n}) ∙ (delta-fmap tailDelta)) ∙ tailDelta) ds
+hoge (delta ds ds₁) = refl
+
+
+

-- Monad-laws (Category)
-{-
-
-monad-law-1-5 : {l : Level} {A : Set l} -> (m : Nat) (n : Nat) -> (ds : Delta (Delta A)) ->
-  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) (delta-bind (mono ds) (n-tail O))     ≡⟨ refl ⟩
-  n-tail (S n) ds                              ≡⟨ refl ⟩
-  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) (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 (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 ⟩
-  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 (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)  ⟩
-  n-tail (n + m) ds                                  ≡⟨ cong (\n -> n-tail n ds) (nat-add-sym n m) ⟩
-  n-tail (m + n) ds                                  ≡⟨ refl ⟩
-  ((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 ⟩
-  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 (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) (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) (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) (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) (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 : join . delta-fmap join = join . join
+monad-law-1 : {l : Level} {A : Set l} {n : Nat} (d : Delta (Delta (Delta A (S n)) (S n)) (S n)) ->
+              ((delta-mu ∙ (delta-fmap delta-mu)) d) ≡ ((delta-mu ∙ delta-mu) d)
+monad-law-1 {n =   O} (mono d)     = refl
+monad-law-1 {n = S O} (delta (delta (delta _ _) _) (mono (delta (delta _ (mono _)) (mono (delta _ (mono _)))))) = refl
+monad-law-1 {n = S n} (delta (delta (delta x d) dd) ds) = begin
+  (delta-mu ∙ delta-fmap delta-mu) (delta (delta (delta x d) dd) ds) ≡⟨ refl ⟩
+  delta-mu (delta-fmap delta-mu (delta (delta (delta x d) dd) ds)) ≡⟨ refl ⟩
+  delta-mu (delta (delta-mu (delta (delta x d) dd)) (delta-fmap delta-mu ds)) ≡⟨ refl ⟩
+  delta-mu (delta (delta (headDelta (delta x d)) (delta-mu (delta-fmap tailDelta dd))) (delta-fmap delta-mu ds)) ≡⟨ refl ⟩
+  delta-mu (delta (delta x (delta-mu (delta-fmap tailDelta dd))) (delta-fmap delta-mu ds)) ≡⟨ refl ⟩
+  delta (headDelta (delta x (delta-mu (delta-fmap tailDelta dd)))) (delta-mu (delta-fmap tailDelta (delta-fmap delta-mu ds))) ≡⟨ refl ⟩
+  delta x (delta-mu (delta-fmap tailDelta (delta-fmap delta-mu ds)))
+  ≡⟨ cong (\de -> delta x (delta-mu de)) (sym (functor-law-2 tailDelta delta-mu ds)) ⟩
+  delta x (delta-mu (delta-fmap (tailDelta {n = n} ∙ delta-mu {n = (S n)}) ds))
+--  ≡⟨ cong (\ff -> delta x (delta-mu (delta-fmap ff ds))) hoge ⟩
+  ≡⟨ {!!} ⟩
+  delta x (delta-mu (delta-fmap (((delta-mu {n = n}) ∙ (delta-fmap tailDelta)) ∙ tailDelta) ds))
+  ≡⟨ cong (\de -> delta x (delta-mu de)) (functor-law-2 (delta-mu ∙ (delta-fmap tailDelta)) tailDelta ds ) ⟩
+  delta x (delta-mu (delta-fmap ((delta-mu {n = n}) ∙ (delta-fmap tailDelta)) (delta-fmap tailDelta ds)))
+  ≡⟨ cong (\de -> delta x (delta-mu de)) (functor-law-2 delta-mu (delta-fmap tailDelta) (delta-fmap tailDelta ds)) ⟩
+  delta x (delta-mu (delta-fmap (delta-mu {n = n}) (delta-fmap (delta-fmap tailDelta) (delta-fmap tailDelta ds))))
+  ≡⟨ cong (\de -> delta x de) (monad-law-1 (delta-fmap (delta-fmap tailDelta) (delta-fmap tailDelta ds)))  ⟩
+  delta x (delta-mu (delta-mu (delta-fmap (delta-fmap tailDelta) (delta-fmap tailDelta ds))))
+  ≡⟨ cong (\de -> delta x (delta-mu de)) (delta-mu-is-nt tailDelta (delta-fmap tailDelta ds)) ⟩
+  delta x (delta-mu (delta-fmap tailDelta (delta-mu (delta-fmap tailDelta ds)))) ≡⟨ refl ⟩
+  delta (headDelta (delta x d)) (delta-mu (delta-fmap tailDelta (delta-mu (delta-fmap tailDelta ds)))) ≡⟨ refl ⟩
+  delta-mu (delta (delta x d) (delta-mu (delta-fmap tailDelta ds))) ≡⟨ refl ⟩
+  delta-mu (delta (headDelta (delta (delta x d) dd)) (delta-mu (delta-fmap tailDelta ds))) ≡⟨ refl ⟩
+  delta-mu (delta-mu (delta (delta (delta x d) dd) ds)) ≡⟨ refl ⟩
+  (delta-mu ∙ delta-mu) (delta (delta (delta x d) dd) ds)
∎
-monad-law-1-4 (S m) n (mono dd) = begin
-  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 (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) (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 (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))) ->
-  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
-  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)
+{-
+begin
+  (delta-mu ∙ delta-fmap delta-mu) (delta d ds) ≡⟨ refl ⟩
+  delta-mu (delta-fmap delta-mu (delta d ds)) ≡⟨ refl ⟩
+  delta-mu (delta (delta-mu d) (delta-fmap delta-mu ds)) ≡⟨ refl ⟩
+  delta (headDelta (delta-mu d)) (delta-mu (delta-fmap tailDelta (delta-fmap delta-mu ds))) ≡⟨ {!!} ⟩
+  delta (headDelta (headDelta d)) (delta-mu (delta-fmap tailDelta (delta-mu (delta-fmap tailDelta ds)))) ≡⟨ refl ⟩
+  delta-mu (delta (headDelta d) (delta-mu (delta-fmap tailDelta ds))) ≡⟨ refl ⟩
+  delta-mu (delta-mu (delta d ds)) ≡⟨ refl ⟩
+  (delta-mu ∙ delta-mu) (delta d ds)
∎
-monad-law-1-3 (S n) (mono (mono d)) = begin
-  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 ⟩
-  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
-  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
-  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
-  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))) -> ((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
-  (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) -> (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
-  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
-  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
-  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
-  ∎
-
-
--- 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) ->
-  (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
-  (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 ⟩
-  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) -> (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) -> (delta-eta ∙ f) x ≡ (delta-fmap f ∙ delta-eta) x
-monad-law-3 f x = refl
-
-
-monad-law-4-1 : {l  : Level} {A B : Set l} -> (n : Nat) -> (f : A -> B) -> (ds : Delta (Delta A)) ->
-  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
-  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
-  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 (delta-bind (mono d) (n-tail (S n)))
-  ∎
-monad-law-4-1 (S n) f (delta d ds) = begin
-  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)))                                                           ∎
+delta-right-unity-law : {l : Level} {A : Set l} {n : Nat} (d : Delta A (S n)) -> (delta-mu ∙ delta-eta) d ≡ id d
+delta-right-unity-law (mono x)    = refl
+delta-right-unity-law (delta x d) = begin
+  (delta-mu ∙ delta-eta) (delta x d)
+  ≡⟨ refl ⟩
+  delta-mu (delta-eta (delta x d))
+  ≡⟨ refl ⟩
+  delta-mu (delta (delta x d) (delta-eta (delta x d)))
+  ≡⟨ refl ⟩
+  delta (headDelta (delta x d)) (delta-mu (delta-fmap tailDelta (delta-eta (delta x d))))
+  ≡⟨ refl ⟩
+  delta x (delta-mu (delta-fmap tailDelta (delta-eta (delta x d))))
+  ≡⟨ cong (\de -> delta x (delta-mu de)) (sym (delta-eta-is-nt  tailDelta (delta x d))) ⟩
+  delta x (delta-mu (delta-eta (tailDelta (delta x d))))
+  ≡⟨ refl ⟩
+  delta x (delta-mu (delta-eta d))
+  ≡⟨ cong (\de -> delta x de) (delta-right-unity-law d) ⟩
+  delta x d
+  ≡⟨ refl ⟩
+  id (delta x d)  ∎

--- 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)) ->
-              (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
-  (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
-  (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-left-unity-law  : {l : Level} {A : Set l} {n : Nat} -> (d : Delta A (S n)) ->
+                                             (delta-mu  ∙ (delta-fmap delta-eta)) d ≡ id d
+delta-left-unity-law (mono x)    = refl
+delta-left-unity-law {n = (S n)} (delta x d) = begin
+  (delta-mu ∙ delta-fmap delta-eta) (delta x d)            ≡⟨ refl ⟩
+  delta-mu ( delta-fmap delta-eta (delta x d))             ≡⟨ refl ⟩
+  delta-mu (delta (delta-eta x) (delta-fmap delta-eta d))  ≡⟨ refl ⟩
+  delta (headDelta {n = S n} (delta-eta x)) (delta-mu (delta-fmap tailDelta (delta-fmap delta-eta d)))  ≡⟨ refl ⟩
+  delta x (delta-mu (delta-fmap tailDelta (delta-fmap delta-eta d)))
+  ≡⟨ cong (\de -> delta x (delta-mu de)) (sym (functor-law-2 tailDelta delta-eta d)) ⟩
+  delta x (delta-mu (delta-fmap (tailDelta ∙ delta-eta {n = S n}) d))  ≡⟨ refl ⟩
+  delta x (delta-mu (delta-fmap (delta-eta {n = n}) d))  ≡⟨ cong (\de -> delta x de) (delta-left-unity-law d) ⟩
+  delta x d ≡⟨ refl ⟩
+  id (delta x d)  ∎

--}
--- monad-law-1 : join . delta-fmap join = join . join
-monad-law-1 : {l : Level} {A : Set l} {a : Rev} -> (d : Delta (Delta (Delta A a) a) a) ->
-            ((delta-mu ∙ (delta-fmap delta-mu)) d) ≡ ((delta-mu ∙ delta-mu) d)
-monad-law-1 (mono d)     = refl
-monad-law-1 (delta d ds) = {!!}
+

-delta-is-monad : {l : Level} {v : Rev} -> Monad {l} (\A -> Delta A v)  delta-is-functor
+delta-is-monad : {l : Level} {n : Nat} -> Monad {l} (\A -> Delta A (S n))  delta-is-functor

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' }
+                          eta-is-nt = delta-eta-is-nt;
+                          association-law = monad-law-1;
+                          left-unity-law  = delta-left-unity-law ;
+                          right-unity-law = \x -> (sym (delta-right-unity-law x)) }

@@ -350,7 +144,7 @@

-- Monad-laws (Haskell)
-- monad-law-h-1 : return a >>= k  =  k a
-monad-law-h-1 : {l : Level} {A B : Set l} ->
+monad-law-h-1 : {l : Level} {A B : Set l} ->
(a : A) -> (k : A -> (Delta B)) ->
(delta-return a >>= k)  ≡ (k a)
monad-law-h-1 a k = refl
@@ -365,7 +159,7 @@

-- monad-law-h-3 : m >>= (\x -> f x >>= g)  =  (m >>= f) >>= g
-monad-law-h-3 : {l : Level} {A B C : Set l} ->
+monad-law-h-3 : {l : Level} {A B C : Set l} ->
(m : Delta A)  -> (f : A -> (Delta B)) -> (g : B -> (Delta C)) ->
(delta-bind m (\x -> delta-bind (f x) g)) ≡ (delta-bind (delta-bind m f) g)
monad-law-h-3 (mono x) f g     = refl
@@ -376,4 +170,4 @@

--}
\ No newline at end of file
+-}```