Monoid.agda 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. module Logic.Structure.Monoid where
  2. import Logic.Equivalence
  3. import Logic.Operations as Operations
  4. open Logic.Equivalence using (Equivalence; module Equivalence)
  5. open Operations.Param
  6. data Monoid (A : Set)(Eq : Equivalence A) : Set where
  7. monoid :
  8. (z : A)
  9. (_+_ : A -> A -> A)
  10. (leftId : LeftIdentity Eq z _+_)
  11. (rightId : RightIdentity Eq z _+_)
  12. (assoc : Associative Eq _+_) ->
  13. Monoid A Eq
  14. -- There should be a simpler way of doing this. Local definitions to data declarations?
  15. module Projections where
  16. zero : {A : Set}{Eq : Equivalence A} -> Monoid A Eq -> A
  17. zero (monoid z _ _ _ _) = z
  18. plus : {A : Set}{Eq : Equivalence A} -> Monoid A Eq -> A -> A -> A
  19. plus (monoid _ p _ _ _) = p
  20. leftId : {A : Set}{Eq : Equivalence A}(Mon : Monoid A Eq) -> LeftIdentity Eq (zero Mon) (plus Mon)
  21. leftId (monoid _ _ li _ _) = li
  22. rightId : {A : Set}{Eq : Equivalence A}(Mon : Monoid A Eq) -> RightIdentity Eq (zero Mon) (plus Mon)
  23. rightId (monoid _ _ _ ri _) = ri
  24. assoc : {A : Set}{Eq : Equivalence A}(Mon : Monoid A Eq) -> Associative Eq (plus Mon)
  25. assoc (monoid _ _ _ _ a) = a
  26. module MonoidM {A : Set}{Eq : Equivalence A}(Mon : Monoid A Eq) where
  27. zero = Projections.zero Mon
  28. _+_ = Projections.plus Mon
  29. leftId = Projections.leftId Mon
  30. rightId = Projections.rightId Mon
  31. assoc = Projections.assoc Mon