Created
May 13, 2021 11:51
-
-
Save raehik/be86c19b5efc1936c2bf585ccf26913e to your computer and use it in GitHub Desktop.
Beginner recursion problem from PLFA book
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module plfa.part1.NaturalsMWE where | |
data Bin : Set where | |
⟨⟩ : Bin | |
_O : Bin → Bin | |
_I : Bin → Bin | |
-- {-# TERMINATING #-} | |
dec : Bin -> Bin | |
dec ⟨⟩ = ⟨⟩ | |
dec (⟨⟩ O) = ⟨⟩ | |
dec (b I) = dec (b O) | |
dec (b O) = (dec b) I | |
--------------- | |
-- Peanos | |
data ℕ : Set where | |
zero : ℕ | |
suc : ℕ → ℕ | |
{-# BUILTIN NATURAL ℕ #-} | |
import Relation.Binary.PropositionalEquality as Eq | |
open Eq using (_≡_; refl) | |
open Eq.≡-Reasoning using (begin_; _≡⟨⟩_; _∎) | |
_+_ : ℕ → ℕ → ℕ | |
zero + n = n | |
(suc m) + n = suc (m + n) | |
_*_ : ℕ → ℕ → ℕ | |
zero * n = zero | |
(suc m) * n = n + (m * n) | |
_∸_ : ℕ → ℕ → ℕ | |
m ∸ zero = m | |
zero ∸ suc n = zero | |
suc m ∸ suc n = m ∸ n | |
{-# BUILTIN NATPLUS _+_ #-} | |
{-# BUILTIN NATTIMES _*_ #-} | |
{-# BUILTIN NATMINUS _∸_ #-} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment