Copyright | (C) 2014-2015 Edward Kmett Eric Mertens |
---|---|
License | BSD-style (see the file LICENSE) |
Maintainer | Edward Kmett <ekmett@gmail.com> |
Stability | provisional |
Portability | portable |
Safe Haskell | Safe |
Language | Haskell98 |
This module provides generic deriving tools for monoids and semigroups for product-like structures.
Synopsis
- gmappend :: (Generic a, GSemigroup (Rep a)) => a -> a -> a
- gmempty :: (Generic a, GMonoid (Rep a)) => a
- newtype GenericSemigroupMonoid a = GenericSemigroupMonoid {}
- class GSemigroup f
- class GSemigroup f => GMonoid f
Generic method implementations
Adapter newtype
newtype GenericSemigroupMonoid a Source #
An adapter newtype, suitable for DerivingVia
. Its Semigroup
and
Monoid
instances leverage the Generic
-based defaults defined by
gmappend
and gmempty
. Here is an example of how to use it:
{-# LANGUAGE DerivingVia #-} import Data.Semigroup.Generic data Pair a = MkPair a a deriving (Semigroup
,Monoid
) via (GenericSemigroupMonoid
(Pair a))
Instances
(Generic a, GSemigroup (Rep a)) => Semigroup (GenericSemigroupMonoid a) Source # | |
Defined in Data.Semigroup.Generic (<>) :: GenericSemigroupMonoid a -> GenericSemigroupMonoid a -> GenericSemigroupMonoid a # sconcat :: NonEmpty (GenericSemigroupMonoid a) -> GenericSemigroupMonoid a # stimes :: Integral b => b -> GenericSemigroupMonoid a -> GenericSemigroupMonoid a # | |
(Generic a, GMonoid (Rep a)) => Monoid (GenericSemigroupMonoid a) Source # | |
Defined in Data.Semigroup.Generic mempty :: GenericSemigroupMonoid a # mappend :: GenericSemigroupMonoid a -> GenericSemigroupMonoid a -> GenericSemigroupMonoid a # mconcat :: [GenericSemigroupMonoid a] -> GenericSemigroupMonoid a # |
Internal classes
class GSemigroup f Source #
gmappend'
Instances
GSemigroup (V1 :: Type -> Type) Source # | |
Defined in Data.Semigroup.Generic | |
GSemigroup (U1 :: Type -> Type) Source # | |
Defined in Data.Semigroup.Generic | |
Semigroup a => GSemigroup (K1 i a :: Type -> Type) Source # | |
Defined in Data.Semigroup.Generic | |
(GSemigroup f, GSemigroup g) => GSemigroup (f :*: g) Source # | |
Defined in Data.Semigroup.Generic | |
GSemigroup f => GSemigroup (M1 i c f) Source # | |
Defined in Data.Semigroup.Generic |
class GSemigroup f => GMonoid f Source #
gmempty'
Instances
GMonoid (U1 :: Type -> Type) Source # | |
Defined in Data.Semigroup.Generic | |
(Semigroup a, Monoid a) => GMonoid (K1 i a :: Type -> Type) Source # | |
Defined in Data.Semigroup.Generic | |
(GMonoid f, GMonoid g) => GMonoid (f :*: g) Source # | |
Defined in Data.Semigroup.Generic | |
GMonoid f => GMonoid (M1 i c f) Source # | |
Defined in Data.Semigroup.Generic |