module Data.HList.HList
( HList(..)
, Append
) where
import Prelude hiding (reverse)
import Data.Monoid
data HList :: [*] -> * where
HNil :: HList '[]
(:+:) :: x -> HList xs -> HList (x ': xs)
instance Show (HList '[]) where
show _ = "()"
instance (Show a, Show (HList b)) => Show (HList (a ': b)) where
show (x :+: y) = "(" ++ show x ++ "," ++ show y ++ ")"
instance Monoid (HList '[]) where
mempty = HNil
mappend _ _ = HNil
instance (Monoid x, Monoid (HList xs))
=> Monoid (HList (x ': xs))
where
mempty = mempty :+: mempty
mappend (x1 :+: xs1) (x2 :+: xs2) = (x1 `mappend` x2)
:+: (xs1 `mappend` xs2)
type family Append (l1::[*]) (l2::[*]) :: [*]
type instance Append '[] l2 = l2
type instance Append (car1 ': cdr2) l2 = car1 ': Append cdr2 l2