Skip to content

Instantly share code, notes, and snippets.

@puffnfresh
Created August 7, 2013 05:11
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save puffnfresh/6171384 to your computer and use it in GitHub Desktop.
Save puffnfresh/6171384 to your computer and use it in GitHub Desktop.
Factorial with types and values in Agda.
module Fact where
open import Data.Nat
-- Fact at the type-level
data Fact : ℕ → ℕ → Set where
factZero : Fact 0 1
factSuc : {n m : ℕ} → Fact n m → Fact (suc n) ((suc n) * m)
-- Value level
fact : ℕ → ℕ
fact 0 = 1
fact (suc n) = (suc n) * (fact n)
-- Check that they're the same
getFact : ∀ n → Fact n (fact n)
getFact 0 = factZero
getFact (suc n) = factSuc (getFact n)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment