Coind.agda 1004 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. {-# OPTIONS --guardedness #-}
  2. module Coind where
  3. open import Common.IO
  4. open import Common.Level
  5. open import Common.Nat
  6. open import Common.Unit
  7. open import Common.Coinduction renaming (♯_ to sharp; ♭ to flat)
  8. {-
  9. infix 1000 sharp_
  10. postulate
  11. Infinity : ∀ {a} (A : Set a) → Set a
  12. sharp_ : ∀ {a} {A : Set a} → A → Infinity A
  13. flat : ∀ {a} {A : Set a} → Infinity A → A
  14. {-# BUILTIN INFINITY Infinity #-}
  15. {-# BUILTIN SHARP sharp_ #-}
  16. {-# BUILTIN FLAT flat #-}
  17. -}
  18. data Stream (A : Set) : Set where
  19. _::_ : (x : A) (xs : ∞ (Stream A)) → Stream A
  20. ones : Stream Nat
  21. ones = 1 :: (sharp ones)
  22. twos : Stream Nat
  23. twos = 2 :: (sharp twos)
  24. incr : Nat -> Stream Nat
  25. incr n = n :: (sharp (incr (n + 1)))
  26. printStream : Nat -> Stream Nat -> IO Unit
  27. printStream zero _ = putStrLn ""
  28. printStream (suc steps) (n :: ns) =
  29. printNat n ,,
  30. printStream steps (flat ns)
  31. main : IO Unit
  32. main =
  33. printStream 10 twos ,,
  34. printStream 10 ones ,,
  35. printStream 10 (incr zero)