Skip to content

Instantly share code, notes, and snippets.

@useronym
Created November 28, 2018 12:57
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save useronym/2a6c8ddd9448448e5f68dd038da2e592 to your computer and use it in GitHub Desktop.
Save useronym/2a6c8ddd9448448e5f68dd038da2e592 to your computer and use it in GitHub Desktop.
open import Data.Nat
open import Data.Bool
mutual
data Stream (A : Set) : Set where
[]ˢ : Stream A
_∷ˢ_ : A → ∞Stream A → Stream A
record ∞Stream (A : Set) : Set where
coinductive
field
force : Stream A
open ∞Stream public
even? : ℕ → Bool
even? zero = true
even? (suc zero) = false
even? (suc (suc n)) = even? n
step : ℕ → ℕ
step n with even? n
… | true = ⌊ n /2⌋
… | false = 3 * n + 1
collatz : ℕ → Stream ℕ
collatz 1 = 1 ∷ˢ λ where .force → []ˢ
collatz n = n ∷ˢ λ where .force → collatz (step n)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment