Skip to content

Instantly share code, notes, and snippets.

@useronym
Created November 28, 2018 12:57
Show Gist options
  • 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