-
-
Save Solonarv/7fcb6fb398218b761e88b92df8a84199 to your computer and use it in GitHub Desktop.
Haskell Peano Arithmetic
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
{-# 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