Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a List Monad #4

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions src/Categories/Examples/Monad/Sets.agda
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{-# OPTIONS --safe --without-K #-}
module Categories.Examples.Monad.Sets where

open import Category.Monad using (RawMonad)
import Data.List as List
import Data.List.Properties
open import Relation.Binary.PropositionalEquality using (refl; sym)

open import Categories.Category.Instance.Sets
open import Categories.Monad using (Monad)
open import Categories.NaturalTransformation using (ntHelper)

import Categories.Examples.Functor.Sets as F

Raw : ∀ {o} (M : Monad (Sets o)) → RawMonad (Monad.F.F₀ M)
Raw M = record
{ return = Monad.η.η M _
; _>>=_ = λ Ma f → Monad.μ.η M _ (Monad.F.F₁ M f Ma)
}

List : ∀ {o} → Monad (Sets o)
List = record
{ F = F.List
; η = record
{ η = λ _ → List.[_]
; commute = λ _ → refl
; sym-commute = λ _ → refl
}
; μ = ntHelper record
{ η = λ _ → List.concat
; commute = λ _ {x} → concat-map x
}
; assoc = λ {_} {x} → concat-concat x
; sym-assoc = λ {_} {x} → sym (concat-concat x)
; identityˡ = concat-[-] _
; identityʳ = ++-identityʳ _
}
where
open Data.List.Properties