Skip to content

Instantly share code, notes, and snippets.

@larrytheliquid
Created August 19, 2010 23:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save larrytheliquid/539197 to your computer and use it in GitHub Desktop.
Save larrytheliquid/539197 to your computer and use it in GitHub Desktop.
module Decimal where
open import Data.Nat
infixr 5 _∷_
infixl 8 _^_
_^_ : ℕ → ℕ → ℕ
n ^ zero = 1
n ^ (suc m) = n * (n ^ m)
data Decimal : ℕ → ℕ → Set where
[_] : (n : ℕ) → Decimal 1 n
_∷_ : ∀ {place val} → (n : ℕ) → Decimal place val → Decimal (suc place) (n * 10 ^ place + val)
decimal-7 : Decimal 1 7
decimal-7 = [ 7 ]
-- invalid-decimal-7 : Decimal 4 7
-- invalid-decimal-7 = [ 7 ]
decimal-648 : Decimal 3 648
decimal-648 = 6 ∷ 4 ∷ [ 8 ]
-- invalid-decimal-648 : Decimal 3 99
-- invalid-decimal-648 = 6 ∷ 4 ∷ [ 8 ]
decimal-021 : Decimal 3 21
decimal-021 = 0 ∷ 2 ∷ [ 1 ]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment