Issue2909-4.agda 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. {-# OPTIONS --guardedness #-}
  2. open import Agda.Builtin.Char
  3. open import Agda.Builtin.Coinduction
  4. open import Agda.Builtin.IO
  5. open import Agda.Builtin.List
  6. open import Agda.Builtin.Unit
  7. open import Agda.Builtin.String
  8. data Colist {a} (A : Set a) : Set a where
  9. [] : Colist A
  10. _∷_ : A → ∞ (Colist A) → Colist A
  11. {-# FOREIGN GHC
  12. data Colist a = Nil | Cons a (MAlonzo.RTE.Inf (Colist a))
  13. type Colist' l a = Colist a
  14. fromColist :: Colist a -> [a]
  15. fromColist Nil = []
  16. fromColist (Cons x xs) = x : fromColist (MAlonzo.RTE.flat xs)
  17. #-}
  18. {-# COMPILE GHC Colist = data Colist' (Nil | Cons) #-}
  19. to-colist : ∀ {a} {A : Set a} → List A → Colist A
  20. to-colist [] = []
  21. to-colist (x ∷ xs) = x ∷ ♯ to-colist xs
  22. a-definition-that-uses-♭ :
  23. ∀ {a} {A : Set a} → Colist A → Colist A
  24. a-definition-that-uses-♭ [] = []
  25. a-definition-that-uses-♭ (x ∷ xs) =
  26. x ∷ ♯ a-definition-that-uses-♭ (♭ xs)
  27. postulate
  28. putStr : Colist Char → IO ⊤
  29. {-# COMPILE GHC putStr = putStr . fromColist #-}
  30. main : IO ⊤
  31. main = putStr (a-definition-that-uses-♭
  32. (to-colist (primStringToList "apa\n")))