-
Notifications
You must be signed in to change notification settings - Fork 246
/
Copy pathFreeMonoid.agda
102 lines (76 loc) · 2.87 KB
/
FreeMonoid.agda
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
------------------------------------------------------------------------
-- The Agda standard library
--
-- The free MonoidAction on a SetoidAction, arising from ListAction
------------------------------------------------------------------------
{-# OPTIONS --cubical-compatible --safe #-}
open import Relation.Binary.Bundles using (Setoid)
module Algebra.Action.Construct.FreeMonoid
{a c r ℓ} (S : Setoid c ℓ) (A : Setoid a r)
where
open import Algebra.Action.Bundles
open import Algebra.Action.Structures using (IsLeftAction; IsRightAction)
open import Algebra.Bundles using (Monoid)
open import Algebra.Structures using (IsMonoid)
open import Data.List.Base using (List; []; _++_)
import Data.List.Properties as List
import Data.List.Relation.Binary.Equality.Setoid as ≋
open import Data.Product.Base using (_,_)
open import Function.Base using (_∘_)
open import Level using (Level; _⊔_)
------------------------------------------------------------------------
-- Temporary: define the Monoid structure on List S.Carrier
-- NB should be defined somewhere under `Data.List`!?
private
open ≋ S using (_≋_; ≋-refl; ≋-reflexive; ≋-isEquivalence; ++⁺)
isMonoid : IsMonoid _≋_ _++_ []
isMonoid = record
{ isSemigroup = record
{ isMagma = record
{ isEquivalence = ≋-isEquivalence
; ∙-cong = ++⁺
}
; assoc = λ xs ys zs → ≋-reflexive (List.++-assoc xs ys zs)
}
; identity = (λ _ → ≋-refl) , ≋-reflexive ∘ List.++-identityʳ
}
monoid : Monoid c (c ⊔ ℓ)
monoid = record { isMonoid = isMonoid }
------------------------------------------------------------------------
-- A Setoid action yields an iterated ListS action, which is
-- the underlying SetoidAction of the FreeMonoid construction
module SetoidActions where
open SetoidAction
open ≋ S renaming (≋-setoid to ListS)
leftAction : (left : Left S A) → Left ListS A
leftAction left = record
{ isLeftAction = record
{ _▷_ = _▷⋆_
; ▷-cong = ▷⋆-cong
}
}
where open Left left
rightAction : (right : Right S A) → Right ListS A
rightAction right = record
{ isRightAction = record
{ _◁_ = _◁⋆_
; ◁-cong = ◁⋆-cong
}
}
where open Right right
------------------------------------------------------------------------
-- Now: define the MonoidActions of the (Monoid based on) ListS on A
module MonoidActions where
open MonoidAction monoid A
leftAction : (left : SetoidAction.Left S A) → Left (SetoidActions.leftAction left)
leftAction left = record
{ ∙-act = ++-act
; ε-act = []-act
}
where open SetoidAction.Left left
rightAction : (right : SetoidAction.Right S A) → Right (SetoidActions.rightAction right)
rightAction right = record
{ ∙-act = ++-act
; ε-act = []-act
}
where open SetoidAction.Right right