Skip to content

Instantly share code, notes, and snippets.

@raichoo
Last active May 10, 2016 20:19
Show Gist options
  • Save raichoo/2bbbbd0c8dae5f7a4620a043ff72cb54 to your computer and use it in GitHub Desktop.
Save raichoo/2bbbbd0c8dae5f7a4620a043ff72cb54 to your computer and use it in GitHub Desktop.
Oh… this works.
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE GADTs #-}
module PlusZero where
import Data.Type.Equality
data Nat
= Zero
| Succ Nat
type family Plus (n :: Nat) (m :: Nat) :: Nat where
Plus 'Zero m = m
Plus ('Succ n) m = 'Succ (Plus n m)
data SNat (n :: Nat) where
SZero :: SNat 'Zero
SSucc :: SNat n -> SNat ('Succ n)
congSucc :: a :~: b -> 'Succ a :~: 'Succ b
congSucc Refl = Refl
plusZero :: SNat n -> Plus n 'Zero :~: n
plusZero SZero = Refl
plusZero (SSucc n) = congSucc (plusZero n)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment