reorganize and add plfa

This commit is contained in:
hellerve committed 2020-06-05 09:18:15 +02:00
1 parent 5bf71e63e7
commit d425272d94
5 files changed
+72

No files matched your search

+68
View File
@@ -0,0 +1,68 @@
module Naturals where
import Relation.Binary.PropositionalEquality as Eq
open Eq using (_≡_; refl)
open Eq.≡-Reasoning using (begin_; _≡⟨⟩_; _∎)
data ℕ : Set where
zero : ℕ
suc : ℕ → ℕ
{-# BUILTIN NATURAL ℕ #-}
_+_ : ℕ → ℕ → ℕ
zero + n = n
suc m + n = suc (m + n)
_*_ : ℕ → ℕ → ℕ
zero * n = zero
suc m * n = n + (m * n)
_^_ : ℕ → ℕ → ℕ
n ^ 0 = 1
n ^ suc m = n * (n ^ m)
_∸_ : ℕ → ℕ → ℕ
m ∸ zero = m
zero ∸ suc n = zero
suc m ∸ suc n = m ∸ n
infixl 6 _+_ _∸_
infixl 7 _*_
{-# BUILTIN NATPLUS _+_ #-}
{-# BUILTIN NATTIMES _*_ #-}
{-# BUILTIN NATMINUS _∸_ #-}
-- Bin stretch exercise
data Bin : Set where
⟨⟩ : Bin
_O : Bin → Bin
_I : Bin → Bin
inc : Bin → Bin
inc ⟨⟩ = ⟨⟩ I
inc (m O) = m I
inc (m I) = (inc m) O
_ : inc (⟨⟩ I O I I) ≡ ⟨⟩ I I O O
_ = refl
_ : inc (⟨⟩ I) ≡ ⟨⟩ I O
_ = refl
to : ℕ -> Bin
to 0 = ⟨⟩
to (suc n) = inc (to n)
_ : to 11 ≡ ⟨⟩ I O I I
_ = refl
from : Bin -> ℕ
from ⟨⟩ = 0
from (m O) = 2 * from m
from (m I) = 1 + 2 * from m
_ : from (⟨⟩ I O I I) ≡ 11
_ = refl
+4
View File
@@ -0,0 +1,4 @@
# PLFA
I’m following along [PLFA](https://plfa.github.io/). This repo only contains the
stretch exercises and supporting materials.
View File
File renamed without changes.
View File
File renamed without changes.
View File
File renamed without changes.