Created
November 28, 2018 12:57
-
-
Save useronym/2a6c8ddd9448448e5f68dd038da2e592 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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