Skip to content

Instantly share code, notes, and snippets.

Created September 9, 2014 15:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/77fe0d1a6525c9e78d42 to your computer and use it in GitHub Desktop.
Save anonymous/77fe0d1a6525c9e78d42 to your computer and use it in GitHub Desktop.
{-# LANGUAGE UndecidableInstances #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# 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
class VecReverse n m where
vecReverse :: Vect n -> Vect m -> Vect (Plus n m)
instance VecReverse Z m where
vecReverse _ w = w
instance (VecReverse n (S m), Plus n (S m) ~ S (Plus n m)) => VecReverse (S n) m where
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