Skip to content

Instantly share code, notes, and snippets.

@nvanderw
Created March 19, 2014 15:09
Show Gist options
  • Save nvanderw/9643739 to your computer and use it in GitHub Desktop.
Save nvanderw/9643739 to your computer and use it in GitHub Desktop.
Proof that numbers go even-odd-even-odd...
{-# LANGUAGE DataKinds, KindSignatures, GADTs #-}
data Nat = Zero | Succ Nat
data Even :: Nat -> * where
Even_base :: Even Zero
Even_induct :: Even k -> Even (Succ (Succ k))
data Odd :: Nat -> * where
Odd_base :: Odd (Succ Zero)
Odd_induct :: Odd k -> Odd (Succ (Succ k))
-- Proof that numbers go even-odd-even-odd...
evenOdd :: Even n -> Odd (Succ n)
evenOdd Even_base = Odd_base
evenOdd (Even_induct k) = let ih = evenOdd k -- inductive hypothesis
in Odd_induct ih
oddEven :: Odd n -> Even (Succ n)
oddEven Odd_base = Even_induct Even_base
oddEven (Odd_induct k) = let ih = oddEven k
in Even_induct ih
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment