1
1
------------------------------------------------------------------------
2
-- Basic types related to coinduction
2
3
------------------------------------------------------------------------
4
5
{-# OPTIONS --universe-polymorphism #-}
7
7
module Coinduction where
13
codata ∞ {a} (A : Set a) : Set a where
16
♭ : ∀ {a} {A : Set a} → ∞ A → A
11
------------------------------------------------------------------------
12
-- A type used to make recursive arguments coinductive
17
∞ : ∀ {a} (A : Set a) → Set a
18
♯_ : ∀ {a} {A : Set a} → A → ∞ A
19
♭ : ∀ {a} {A : Set a} → ∞ A → A
21
{-# BUILTIN INFINITY ∞ #-}
22
{-# BUILTIN SHARP ♯_ #-}
23
{-# BUILTIN FLAT ♭ #-}
25
------------------------------------------------------------------------
26
-- Rec, a type which is analogous to the Rec type constructor used in
27
-- (the current version of) ΠΣ
29
data Rec {a} (A : ∞ (Set a)) : Set a where
30
fold : (x : ♭ A) → Rec A
32
unfold : ∀ {a} {A : ∞ (Set a)} → Rec A → ♭ A
37
-- If --guardedness-preserving-type-constructors is enabled one can
38
-- define types like ℕ by recursion:
52
ℕ-rec : (P : ℕ → Set) →
54
(∀ n → P n → P (suc n)) →
56
ℕ-rec P z s (inj₁ _) = z
57
ℕ-rec P z s (inj₂ (fold n)) = s n (ℕ-rec P z s n)
59
-- This feature is very experimental, though: it may lead to