mirror of
https://git8.cs.fau.de/theses/bsc-leon-vatthauer.git
synced 2024-05-31 07:28:34 +02:00
update code examples
This commit is contained in:
parent
7f3330f45c
commit
4d8bb098af
3 changed files with 10 additions and 15 deletions
|
@ -8,6 +8,7 @@ main = do
|
|||
print (hd []::[String])
|
||||
|
||||
reverse :: [a] -> [a]
|
||||
reverse = reverseAcc []
|
||||
reverse l = reverseAcc l []
|
||||
where
|
||||
reverseAcc = foldl (flip (:))
|
||||
reverseAcc [] a = a
|
||||
reverseAcc (x:xs) a = reverseAcc xs (x:a)
|
||||
|
|
|
@ -13,16 +13,12 @@ module reverse where
|
|||
now : A → Delay A
|
||||
later : ∞ (Delay A) → Delay A
|
||||
|
||||
foldl : ∀ {A B : Set} → (A → B → A) → A → Colist B → Delay A
|
||||
foldl c n [] = now n
|
||||
foldl c n (x ∷ xs) = later (♯ foldl c (c n x) (♭ xs))
|
||||
|
||||
-- reversing possibly infinite lists
|
||||
reverse : ∀ {A : Set} → Colist A → Delay (Colist A)
|
||||
reverse {A} = reverseAcc []
|
||||
where
|
||||
reverseAcc : Colist A → Colist A → Delay (Colist A)
|
||||
reverseAcc = foldl (λ xs x → x ∷ (♯ xs)) -- 'flip _∷_' with extra steps
|
||||
reverseAcc [] a = now a
|
||||
reverseAcc (x ∷ xs) a = later (♯ reverseAcc (♭ xs) (x ∷ (♯ a)))
|
||||
|
||||
run_for_steps : ∀ {A : Set} → Delay A → ℕ → Delay A
|
||||
run now x for n steps = now x
|
||||
|
|
|
@ -19,9 +19,10 @@ head (x:xs) = x
|
|||
\vskip 1cm
|
||||
\begin{minted}{agda}
|
||||
reverse :: [a] -> [a]
|
||||
reverse = reverseAcc []
|
||||
reverse l = reverseAcc l []
|
||||
where
|
||||
reverseAcc = foldl (flip (:))
|
||||
reverseAcc [] a = a
|
||||
reverseAcc (x:xs) a = reverseAcc xs (x:a)
|
||||
\end{minted}
|
||||
|
||||
\mycallout<4->{21, 2}{
|
||||
|
@ -83,14 +84,11 @@ run later x for suc n steps = run ♭ x for n steps
|
|||
\begin{frame}[c, fragile]{Partiality in Agda}{Reversing (possibly infinite) lists}
|
||||
\centering
|
||||
\begin{minted}{agda}
|
||||
foldl : ∀ {A B : Set} → (A → B → A) → A → Colist B → Delay A
|
||||
foldl c n [] = now n
|
||||
foldl c n (x ∷ xs) = later (♯ foldl c (c n x) (♭ xs))
|
||||
|
||||
reverse : ∀ {A : Set} → Colist A → Delay (Colist A)
|
||||
reverse {A} = reverseAcc []
|
||||
where
|
||||
reverseAcc : Colist A → Colist A → Delay (Colist A)
|
||||
reverseAcc = foldl (λ xs x → x ∷ (♯ xs))
|
||||
reverseAcc [] a = now a
|
||||
reverseAcc (x ∷ xs) a = later (♯ reverseAcc (♭ xs) (x ∷ (♯ a)))
|
||||
\end{minted}
|
||||
\end{frame}
|
Loading…
Reference in a new issue