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