Issue1062.lagda 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. \nonstopmode
  2. \documentclass{article}
  3. \usepackage{agda}
  4. \begin{document}
  5. \begin{code}
  6. {-# OPTIONS --copatterns --sized-types #-}
  7. {-# BUILTIN SIZE Size #-}
  8. {-# BUILTIN SIZELT Size<_ #-}
  9. {-# BUILTIN SIZESUC ↑_ #-}
  10. {-# BUILTIN SIZEINF ∞ #-}
  11. data List (A : Set) : Set where
  12. [] : List A
  13. _∷_ : (x : A) (xs : List A) -> List A
  14. record _×_ (A B : Set) : Set where
  15. constructor _,_
  16. field
  17. fst : A
  18. snd : B
  19. open _×_
  20. -- Sized streams via head/tail.
  21. record Stream {i : Size} (A : Set) : Set where
  22. coinductive; constructor _∷_
  23. field
  24. head : A
  25. tail : ∀ {j : Size< i} → Stream {j} A
  26. open Stream public
  27. _∷ˢ_ : ∀ {i A} → A → Stream {i} A → Stream {↑ i} A
  28. head (a ∷ˢ as) = a
  29. tail (a ∷ˢ as) = as
  30. -- Streams and lists.
  31. -- Prepending a list to a stream.
  32. _++ˢ_ : ∀ {i A} → List A → Stream {i} A → Stream {i} A
  33. [] ++ˢ s = s
  34. (a ∷ as) ++ˢ s = a ∷ˢ (as ++ˢ s)
  35. -- Unfold which produces several outputs at one step
  36. record List1 (A : Set) : Set where
  37. constructor _∷_
  38. field
  39. head : A
  40. tail : List A
  41. open List1 using (head; tail)
  42. record ⊤ : Set where constructor trivial
  43. open List1 (trivial ∷ []) using (head; tail) -- problem: imports not colored
  44. unfold⁺ : ∀ {S : Size → Set} {A : Set}
  45. (step : ∀ {i} → S i → List1 A × (∀ {j : Size< i} → S j)) →
  46. ∀ {i} → (s : S i) → Stream {i} A
  47. head (unfold⁺ step s) = head (fst (step s))
  48. tail (unfold⁺ step s) = let ((_ ∷ l) , s′) = step s
  49. in l ++ˢ unfold⁺ step s′
  50. \end{code}
  51. Problem: The ∷ in the last let statement is not colored with constructor color.
  52. \end{document}