bsc-leon-vatthauer/slides/code-examples/reverse.agda
2024-01-23 13:25:18 +01:00

36 lines
No EOL
1 KiB
Agda
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

{-# OPTIONS --guardedness #-}
open import Codata.Musical.Notation
open import Data.Nat
module reverse where
data Delay (A : Set) : Set where
now : A Delay A
later : (Delay A) Delay A
run_for_steps : {A : Set} Delay A Delay A
run now x for n steps = now x
run later x for zero steps = later x
run later x for suc n steps = run x for n steps
never : {A : Set} Delay A
never = later ( never)
data Colist (A : Set) : Set where
[] : Colist A
_∷_ : A (Colist A) Colist A
reverse : {A : Set} Colist A Delay (Colist A)
reverse {A} l = reverseAcc l []
where
reverseAcc : Colist A Colist A Delay (Colist A)
reverseAcc [] a = now a
reverseAcc (x xs) a = later ( reverseAcc ( xs) (x ( a)))
fin-colist : Colist
fin-colist = 1 (2 (3 []))
ones : Colist
ones = 1 ones
-- run reverse fin-colist for 5 steps
-- run reverse ones for 1000 steps