Skip to content

Instantly share code, notes, and snippets.

@bishboria
Last active October 23, 2016 13:14
Show Gist options
  • Save bishboria/5687015 to your computer and use it in GitHub Desktop.
Save bishboria/5687015 to your computer and use it in GitHub Desktop.
Exercise: Encode multiplication as a type in Agda
-- This was an exercise: to encode _×_≡_ using _+_≡_
module Multiplication where
open import Data.Nat using (ℕ; suc; zero)
-- Addition encoded as a type
data _+_≡_ : Set where
zp : {n} zero + n ≡ n
sp : {m n k} m + n ≡ k suc m + n ≡ suc k
-- Multiplication encoded as a type
data _×_≡_ : Set where
zm : {n} zero × n ≡ zero
sm : {m n k i} m × n ≡ k n + k ≡ i suc m × n ≡ i
2×1≡2 : 2 × 12
2×1≡2 = sm (sm zm (sp zp)) (sp zp)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment