### view agda/similar.agda @ 27:742e62fc63e4

author Yasutaka Higa Tue, 07 Oct 2014 14:53:56 +0900 5ba82f107a95 6e6d646d7722
line wrap: on
line source
```
open import list
open import Relation.Binary.PropositionalEquality
open ≡-Reasoning

module similar where

id : {A : Set} -> A -> A
id x = x

postulate String : Set
postulate show   : {A : Set} -> A -> String

data Similar (A : Set) : Set where
similar : List String -> A -> List String -> A -> Similar A

fmap : {A B : Set} -> (A -> B) -> (Similar A) -> (Similar B)
fmap f (similar xs x ys y) = similar xs (f x) ys (f y)

mu : {A : Set} -> Similar (Similar A) -> Similar A
mu (similar lx (similar llx x _ _) ly (similar _ _ lly y)) = similar (lx ++ llx) x (ly ++ lly) y

return : {A : Set} -> A -> Similar A
return x = similar [] x [] x

returnS : {A : Set} -> A -> Similar A
returnS x = similar [[ (show x) ]] x [[ (show x) ]] x

returnSS : {A : Set} -> A -> A -> Similar A
returnSS x y = similar [[ (show x) ]] x [[ (show y) ]] y

_∙_ : {A B C : Set} -> (A -> B) -> (B -> C) -> (A -> C)
f ∙ g = \x -> g (f x)

monad-law-1 : mu ∙ (fmap mu) ≡ mu ∙ mu

--monad-law-2 : mu ∙ fmap return ≡ mu ∙ return ≡id
monad-law-2-1 : mu ∙ fmap return ≡ mu ∙ return