Skip to content

Instantly share code, notes, and snippets.

@Solonarv
Forked from alexpeits/Eliminate.hs
Last active September 5, 2018 20:06
Show Gist options
  • Save Solonarv/7fcb6fb398218b761e88b92df8a84199 to your computer and use it in GitHub Desktop.
Save Solonarv/7fcb6fb398218b761e88b92df8a84199 to your computer and use it in GitHub Desktop.
Haskell Peano Arithmetic
{-# LANGUAGE GADTs #-}
{-# LANGUAGE UndecidableInstances #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeOperators #-}
module Eliminate where
data Nat = Zero | Succ Nat
type family n + m where
Zero + m = E m
Succ n + m = Succ (E n + E m)
type family Pred n where
Pred Zero = Zero
Pred (Succ n) = n
data Vec :: (* -> Nat -> *) where
VNil :: Vec a Zero
(:>) :: a -> Vec a n -> Vec a (Succ n)
(+++) :: Vec a n -> Vec a m -> Vec a (n + m)
VNil +++ ys = ys
(x :> xs) +++ ys = x :> (xs +++ ys)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment