Strict.agda 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. {-# OPTIONS --guardedness #-}
  2. open import Agda.Builtin.Coinduction
  3. open import Agda.Builtin.IO
  4. open import Agda.Builtin.List
  5. open import Agda.Builtin.Nat
  6. open import Agda.Builtin.String
  7. open import Agda.Builtin.Unit
  8. private
  9. variable
  10. A : Set
  11. postulate
  12. putStrLn : String → IO ⊤
  13. {-# FOREIGN GHC import qualified Data.Text.IO #-}
  14. {-# COMPILE GHC putStrLn = Data.Text.IO.putStrLn #-}
  15. record Stream₁ (A : Set) : Set where
  16. coinductive
  17. constructor _∷_
  18. field
  19. head : A
  20. tail : Stream₁ A
  21. open Stream₁
  22. repeat₁ : A → Stream₁ A
  23. repeat₁ x .head = x
  24. repeat₁ x .tail = repeat₁ x
  25. take₁ : Nat → Stream₁ A → List A
  26. take₁ zero xs = []
  27. take₁ (suc n) xs = xs .head ∷ take₁ n (xs .tail)
  28. data List′ (A : Set) : Set where
  29. [] : List′ A
  30. _∷_ : A → List′ A → List′ A
  31. to-list : List′ A → List A
  32. to-list [] = []
  33. to-list (x ∷ xs) = x ∷ to-list xs
  34. data Stream₂ (A : Set) : Set where
  35. _∷_ : A → ∞ (Stream₂ A) → Stream₂ A
  36. repeat₂ : A → Stream₂ A
  37. repeat₂ x = x ∷ ♯ repeat₂ x
  38. take₂ : Nat → Stream₂ A → List′ A
  39. take₂ zero _ = []
  40. take₂ (suc n) (x ∷ xs) = x ∷ take₂ n (♭ xs)
  41. _++_ : List A → List′ A → List A
  42. [] ++ ys = to-list ys
  43. (x ∷ xs) ++ ys = x ∷ (xs ++ ys)
  44. main : IO ⊤
  45. main =
  46. putStrLn
  47. (primStringFromList
  48. (take₁ 3 (repeat₁ '(') ++ take₂ 3 (repeat₂ ')')))