on master help sign in
Add semigroup instance for List
37c466dCsongor Kiss
src/Data/Generics/Product/Internal/List.hs+7
@@ -41,6 +41,7 @@ module Data.Generics.Product.Internal.List
41 ) where
41 ) where
42
42
43import GHC.TypeLits
43import GHC.TypeLits
44+import Data.Semigroup
44
45
45import Data.Kind (Type)
46import Data.Kind (Type)
46import GHC.Generics
47import GHC.Generics
@@ -58,10 +59,16 @@ type family ((as :: [k]) ++ (bs :: [k])) :: [k] where
58 '[] ++ bs = bs
59 '[] ++ bs = bs
59 (a ': as) ++ bs = a ': as ++ bs
60 (a ': as) ++ bs = a ': as ++ bs
60
61
62+instance Semigroup (List '[]) where
63+ _ <> _ = Nil
64+
61instance Monoid (List '[]) where
65instance Monoid (List '[]) where
62 mempty = Nil
66 mempty = Nil
63 mappend _ _ = Nil
67 mappend _ _ = Nil
64
68
69+instance (Semigroup a, Semigroup (List as)) => Semigroup (List ('(k, a) ': as)) where
70+ (x :> xs) <> (y :> ys) = (x <> y) :> (xs <> ys)
71+
65instance (Monoid a, Monoid (List as)) => Monoid (List ('(k, a) ': as)) where
72instance (Monoid a, Monoid (List as)) => Monoid (List ('(k, a) ': as)) where
66 mempty = mempty :> mempty
73 mempty = mempty :> mempty
67 mappend (x :> xs) (y :> ys) = mappend x y :> mappend xs ys
74 mappend (x :> xs) (y :> ys) = mappend x y :> mappend xs ys