Skip to content

Instantly share code, notes, and snippets.

@gergoerdi
Last active November 15, 2017 08:40
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 gergoerdi/ec95524e608aa0daebcceaf724fe20b4 to your computer and use it in GitHub Desktop.
Save gergoerdi/ec95524e608aa0daebcceaf724fe20b4 to your computer and use it in GitHub Desktop.
open import Agda.Builtin.FromNat
open import Data.Fin
open import Relation.Nullary
open import Relation.Nullary.Decidable
open import Data.Nat renaming (_≤?_ to _N≤?_)
open import Data.Unit
instance
NumFin : ∀ {n} → Number (Fin n)
Number.Constraint (NumFin {n}) k = True (suc k N≤? n)
Number.fromNat NumFin m {{m<n}}= #_ m {m<n = m<n}
instance
NumNat : Number ℕ
Number.Constraint NumNat _ = ⊤
Number.fromNat NumNat m = m
data I'mFinnish : Set where
Mk : Fin 5 → I'mFinnish
foo : I'mFinnish
foo = Mk (# 3)
open import Data.Bool
-- This fails with
-- suc is not a constructor of the datatype Fin
-- when checking that the pattern suc (suc (suc zero)) has type Fin (fromNat 5)
bar′ : I'mFinnish → Bool
bar′ (Mk 3) = true
bar′ _ = false
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment