Debian Codegraph @

src/Codata/Sized/M.agda

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