Created
August 19, 2010 23:25
-
-
Save larrytheliquid/539197 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 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