From a90a5df6725ee0e64716f76f112a7098ad059d23 Mon Sep 17 00:00:00 2001 From: Leon Vatthauer Date: Fri, 12 Jan 2024 17:36:59 +0100 Subject: [PATCH] sync --- slides/code-examples/reverse.agda | 21 +++++++++++------- slides/sections/00_intro.tex | 37 +++++++++++++++++++------------ 2 files changed, 36 insertions(+), 22 deletions(-) diff --git a/slides/code-examples/reverse.agda b/slides/code-examples/reverse.agda index f4b4e66..08edbe0 100644 --- a/slides/code-examples/reverse.agda +++ b/slides/code-examples/reverse.agda @@ -1,6 +1,5 @@ {-# OPTIONS --guardedness #-} -open import Codata.Musical.Colist hiding (_++_) -open import Codata.Musical.Colist.Bisimilarity +-- open import Codata.Musical.Colist hiding (_++_) open import Codata.Musical.Notation open import Data.Nat open import Data.Nat.Show renaming (show to showℕ) @@ -13,6 +12,18 @@ module reverse 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 = later (♯ (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} = reverseAcc [] where @@ -20,12 +31,6 @@ module reverse where 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 - 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 ∷ ♯ [])) diff --git a/slides/sections/00_intro.tex b/slides/sections/00_intro.tex index 4302970..1cc8862 100644 --- a/slides/sections/00_intro.tex +++ b/slides/sections/00_intro.tex @@ -1,14 +1,20 @@ \section{Partiality in Type Theory} + +% TODO +% - remove vskips and use begin{listing} +% - add colist definition + \begin{frame}[t, fragile]{Partiality in Haskell}{} + Haskell allows users to define arbitrary partial functions \begin{itemize} - \item<1-> Haskell allows users to define arbitrary partial functions, some can be spotted easily by their definition: - \vskip 1cm - \begin{minted}{agda} + \item<1-> Some can be spotted easily by their definition: + \vskip 0.5cm + \begin{minted}{haskell} head :: [a] -> a head [] = error "empty list" head (x:xs) = x \end{minted} - \mycallout<2->{21, 1.5}{ + \mycallout<2->{22, 1.5}{ ghci> head []\\ *** Exception: empty list\\ CallStack (from HasCallStack):\\ @@ -16,16 +22,16 @@ head (x:xs) = x } \item<3-> others might be more subtle: - \vskip 1cm - \begin{minted}{agda} + \vskip 0.5cm + \begin{minted}{haskell} reverse :: [a] -> [a] -reverse l = reverseAcc l [] +reverse l = revAcc l [] where - reverseAcc [] a = a - reverseAcc (x:xs) a = reverseAcc xs (x:a) + revAcc [] a = a + revAcc (x:xs) a = revAcc xs (x:a) \end{minted} - \mycallout<4->{21, 2}{ + \mycallout<4->{22, 2}{ ghci> ones = 1 : ones\\ ghci> reverse ones\\ ... @@ -39,13 +45,16 @@ In Agda every function has to be total and terminating, so how do we model parti \begin{itemize}[<+->] \item Simple errors can be modelled with the maybe monad + \begin{listing}[H] \begin{minted}{agda} data Maybe (A : Set) : Set where just : A → Maybe A nothing : Maybe A \end{minted} +\end{listing} for head we can then do: + \vskip 0.5cm \begin{minted}{agda} head : ∀ A → List A → Maybe A @@ -85,10 +94,10 @@ run later x for suc n steps = run ♭ x for n steps \centering \begin{minted}{agda} reverse : ∀ {A : Set} → Colist A → Delay (Colist A) -reverse {A} = reverseAcc [] +reverse {A} = revAcc [] where - reverseAcc : Colist A → Colist A → Delay (Colist A) - reverseAcc [] a = now a - reverseAcc (x ∷ xs) a = later (♯ reverseAcc (♭ xs) (x ∷ (♯ a))) + revAcc : Colist A → Colist A → Delay (Colist A) + revAcc [] a = now a + revAcc (x ∷ xs) a = later (♯ revAcc (♭ xs) (x ∷ (♯ a))) \end{minted} \end{frame} \ No newline at end of file