Pay attention to the definition HAppendList:
type family HAppendList (l1 :: [k]) (l2 :: [k]) :: [k]
type instance HAppendList '[] l = l
type instance HAppendList (e ': l) l' = e ': HAppendList l l'
You and I know that []this is a left and right identity ++, but the compiler only knows about the left identifier:
happend' :: T a -> T b -> T (HAppendList a b)
happend' (T (Tagged a)) (T (Tagged b)) = (T (Tagged (a++b)))
-- Doesn't typecheck
leftIdentity' :: T a -> T '[] -> T a
leftIdentity' x y = happend' x y
rightIdentity' :: T '[] -> T a -> T a
rightIdentity' x y = happend' x y
You will need
type instance HAppendList '[] l = l
type instance HAppendList l '[] = l
type instance HAppendList (e ': l) l' = e ': HAppendList l l'
; , . :
(!+++!) :: T a -> T b -> T (HAppendList a b)
(!+++!) (T (Tagged x)) (T (Tagged y)) = T (Tagged (y ++ x))
(!++*) :: Foldable t => T a -> t (T '[]) -> T a
a !++* t = F.foldl (flip (!+++!)) a t
, ghc 7.8, :
type family (++) (a :: [k]) (b :: [k]) :: [k] where
'[] ++ x = x
x ++ '[] = x
(x ': xs) ++ ys = x ': (xs ++ ys)
happend :: T a -> T b -> T (a ++ b)
happend (T (Tagged a)) (T (Tagged b)) = (T (Tagged (a++b)))
leftIdentity :: T a -> T '[] -> T a
leftIdentity x y = happend x y
rightIdentity :: T '[] -> T a -> T a
rightIdentity x y = happend x y