bsc-leon-vatthauer/slides/code-examples/reverse.agda

36 lines
1.1 KiB
Agda
Raw Normal View History

2024-01-03 19:51:04 +01:00
{-# OPTIONS --guardedness #-}
open import Codata.Musical.Colist hiding (_++_)
open import Codata.Musical.Colist.Bisimilarity
open import Codata.Musical.Notation
open import Data.Nat
open import Data.Nat.Show renaming (show to show)
open import Function.Base
open import Relation.Binary.PropositionalEquality
open import Data.String using (String; _++_)
module reverse where
data Delay (A : Set) : Set where
now : A Delay A
later : (Delay A) Delay A
reverse : {A : Set} Colist A Delay (Colist A)
reverse {A} = reverseAcc []
where
reverseAcc : Colist A Colist A Delay (Colist A)
2024-01-11 13:42:27 +01:00
reverseAcc [] a = now a
reverseAcc (x xs) a = later ( reverseAcc ( xs) (x ( a)))
2024-01-03 19:51:04 +01:00
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
fin-colist : Colist
fin-colist = 1 (2 (3 []))
inf-colist : Colist
inf-colist = 1 inf-colist
-- run reverse fin-colist for 5 steps
-- run reverse inf-colist for 1000 steps