Skip to content

Instantly share code, notes, and snippets.

Created September 9, 2014 12:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save anonymous/d838e68ce6a02412859f to your computer and use it in GitHub Desktop.
Save anonymous/d838e68ce6a02412859f to your computer and use it in GitHub Desktop.
{-# LANGUAGE GADTs #-}
{-# LANGUAGE ExistentialQuantification #-}
{-# LANGUAGE Rank2Types #-}
{-# LANGUAGE TypeFamilies #-}
data Z
data S n
type family Plus m n where
Plus Z m = m
Plus (S n) m = S (Plus n m)
data Vect n where
ZV :: Vect Z
CV :: Int -> Vect n -> Vect (S n)
instance Show (Vect n) where
show ZV = "Nil"
show (CV x v) = show x ++ " : " ++ show v
vecReverse :: Vect n -> Vect m -> Vect (Plus n m)
vecReverse ZV w = w
vecReverse (CV x v) w = vecReverse v (CV x w)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment