Debian Codegraph @

src/Codata/Musical/M.agda

raw
1 ------------------------------------------------------------------------
2 -- The Agda standard library
3 --
4 -- M-types (the dual of W-types)
5 ------------------------------------------------------------------------
6
7 {-# OPTIONS --safe --cubical-compatible --guardedness #-}
8
9 module Codata.Musical.M where
10
11 open import Codata.Musical.Notation using (♭; ∞; ♯_)
12 open import Level using (Level; _⊔_)
13 open import Data.Product.Base hiding (map)
14 open import Data.Container.Core as C hiding (map)
15
16 -- The family of M-types.
17
18 data M {s p} (C : Container s p) : Set (s ⊔ p) where
19 inf : ⟦ C ⟧ (∞ (M C)) → M C
20
21 -- Projections.
22
23 module _ {s p} (C : Container s p) where
24
25 head : M C → Shape C
26 head (inf (x , _)) = x
27
28 tail : (x : M C) → Position C (head x) → M C
29 tail (inf (x , f)) b = ♭ (f b)
30
31 -- map
32
33 module _ {s₁ s₂ p₁ p₂} {C₁ : Container s₁ p₁} {C₂ : Container s₂ p₂}
34 (m : C₁ ⇒ C₂) where
35
36 map : M C₁ → M C₂
37 map (inf (x , f)) = inf (shape m x , λ p → ♯ map (♭ (f (position m p))))
38
39
40 -- unfold
41
42 module _ {s p ℓ} {C : Container s p} (open Container C)
43 {S : Set ℓ} (alg : S → ⟦ C ⟧ S) where
44
45 unfold : S → M C
46 unfold seed = let (x , f) = alg seed in
47 inf (x , λ p → ♯ unfold (f p))