on master help sign in
Add semigroup instance for List
commit37c466d8bd0404e0ce169a34548d0aae7226fb40 authorCsongor Kiss <kiss.csongor.kiss@gmail.com> dateThu 25 Jan 2018, 18:38 (9 years ago) parent900cb6f
1 file changed+7
src/Data/Generics/Product/Internal/List.hs+7
src/Data/Generics/Product/Internal/List.hs+7
@@ -41,6 +41,7 @@ module Data.Generics.Product.Internal.List
4141 ) where
4242
4343import GHC.TypeLits
44+import Data.Semigroup
4445
4546import Data.Kind (Type)
4647import GHC.Generics
@@ -58,10 +59,16 @@ type family ((as :: [k]) ++ (bs :: [k])) :: [k] where
5859 '[] ++ bs = bs
5960 (a ': as) ++ bs = a ': as ++ bs
6061
62+instance Semigroup (List '[]) where
63+ _ <> _ = Nil
64+
6165instance Monoid (List '[]) where
6266 mempty = Nil
6367 mappend _ _ = Nil
6468
69+instance (Semigroup a, Semigroup (List as)) => Semigroup (List ('(k, a) ': as)) where
70+ (x :> xs) <> (y :> ys) = (x <> y) :> (xs <> ys)
71+
6572instance (Monoid a, Monoid (List as)) => Monoid (List ('(k, a) ': as)) where
6673 mempty = mempty :> mempty
6774 mappend (x :> xs) (y :> ys) = mappend x y :> mappend xs ys