Created
August 7, 2013 05:11
-
-
Save puffnfresh/6171384 to your computer and use it in GitHub Desktop.
Factorial with types and values in Agda.
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 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