Created
June 21, 2020 11:36
-
-
Save JakobBruenker/01bd15136bcfcec9e75d3e88e7acbe71 to your computer and use it in GitHub Desktop.
TooLong.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 TooLong where | |
open import Agda.Builtin.Nat renaming (Nat to ℕ) | |
open import Agda.Primitive | |
open import Agda.Builtin.Bool | |
open import Agda.Builtin.Equality | |
data SK : Set where | |
S : SK | |
K : SK | |
_`_ : SK → SK → SK | |
infixl 2 _`_ | |
data ℕExtractable : (x : SK) → Set where | |
zero : ℕExtractable (K ` (S ` K ` K)) | |
suc : ∀ {x} → ℕExtractable x | |
→ ℕExtractable (S ` (S ` (K ` S) ` K) ` x) | |
data ⊥ : Set where | |
infix 3 ¬_ | |
¬_ : Set → Set | |
¬ p = p → ⊥ | |
data Dec (P : Set) : Set where | |
yes : P → Dec P | |
no : ¬ P → Dec P | |
-- XXX is there a shorter way to write this? | |
isℕExtractable : (x : SK) → Dec (ℕExtractable x) | |
isℕExtractable (K ` (S ` K ` K)) = yes zero | |
isℕExtractable (S ` (S ` (K ` S) ` K) ` x) with isℕExtractable x | |
... | yes p = yes (suc p) | |
... | no p = no λ q → p (predExt q) | |
where | |
predExt : ∀ {x} -- XXX Can this function be inlined? | |
→ ℕExtractable (S ` (S ` (K ` S) ` K) ` x) | |
→ ℕExtractable x | |
predExt (suc p) = p | |
isℕExtractable S = no λ () | |
isℕExtractable K = no λ () | |
isℕExtractable (S ` x) = no λ () | |
isℕExtractable (K ` S) = no λ () | |
isℕExtractable (K ` K) = no λ () | |
isℕExtractable (K ` (S ` x)) = no λ () | |
isℕExtractable (K ` (K ` x)) = no λ () | |
isℕExtractable (K ` (S ` S ` x)) = no λ () | |
isℕExtractable (K ` (S ` K ` S)) = no λ () | |
isℕExtractable (K ` (S ` K ` (x ` y))) = no λ () | |
isℕExtractable (K ` (S ` (x ` y) ` z)) = no λ () | |
isℕExtractable (K ` (K ` x ` y)) = no λ () | |
isℕExtractable (K ` (x ` y ` z ` w)) = no λ () | |
isℕExtractable (K ` x ` y) = no λ () | |
isℕExtractable (S ` S ` x) = no λ () | |
isℕExtractable (S ` K ` x) = no λ () | |
isℕExtractable (S ` (S ` x) ` y) = no λ () | |
isℕExtractable (S ` (K ` x) ` y) = no λ () | |
isℕExtractable (S ` (S ` S ` y) ` z) = no λ () | |
isℕExtractable (S ` (S ` K ` y) ` z) = no λ () | |
isℕExtractable (S ` (S ` (S ` x₁) ` y) ` z) = no λ () | |
isℕExtractable (S ` (S ` (K ` S) ` S) ` z) = no λ () | |
isℕExtractable (S ` (S ` (K ` S) ` (y ` y₁)) ` z) = no λ () | |
isℕExtractable (S ` (S ` (K ` K) ` x) ` y) = no λ () | |
isℕExtractable (S ` (S ` (K ` (x ` y)) ` z) ` w) = no λ () | |
isℕExtractable (S ` (S ` (x ` y ` z) ` w) ` u) = no λ () | |
isℕExtractable (S ` (K ` x ` y) ` z) = no λ () | |
isℕExtractable (S ` (x ` y ` z ` w) ` v) = no λ () | |
isℕExtractable (x ` y ` z ` w) = no λ () | |
extractℕ : (x : SK) → ℕExtractable x → ℕ | |
extractℕ (K ` (S ` K ` K)) zero = zero | |
extractℕ (S ` (S ` (K ` S) ` K) ` x) (suc p) = suc (extractℕ x p) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Not necessarily shorter but a more principled approach: