Issue2879-2.agda 959 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. {-# OPTIONS --sized-types #-}
  2. open import Agda.Builtin.IO
  3. open import Agda.Builtin.Nat
  4. open import Agda.Builtin.Size
  5. open import Agda.Builtin.Unit
  6. mutual
  7. data Delay (A : Set) (i : Size) : Set where
  8. now : A → Delay A i
  9. later : Delay′ A i → Delay A i
  10. record Delay′ (A : Set) (i : Size) : Set where
  11. coinductive
  12. field
  13. force : {j : Size< i} → Delay A j
  14. open Delay′ public
  15. delay : ∀ {A i} → Nat → A → Delay A i
  16. delay zero x = now x
  17. delay (suc n) x = later λ { .force → delay n x }
  18. data Maybe (A : Set) : Set where
  19. nothing : Maybe A
  20. just : A → Maybe A
  21. {-# COMPILE GHC Maybe = data Maybe (Nothing | Just) #-}
  22. run : ∀ {A} → Nat → Delay A ∞ → Maybe A
  23. run zero _ = nothing
  24. run (suc n) (now x) = just x
  25. run (suc n) (later x) = run n (force x)
  26. postulate
  27. wrapper : Maybe Nat → IO ⊤
  28. {-# COMPILE GHC wrapper = print #-}
  29. main : IO ⊤
  30. main = wrapper (run 10 (delay 5 12))