generic-deriving-1.11.2: Generic programming library for generalised deriving.

Safe HaskellSafe
LanguageHaskell2010

Generics.Deriving.Monoid

Contents

Description

This module provides two main features:

  1. GMonoid, a generic version of the Monoid type class, including instances of the types from Data.Monoid
  2. Default generic definitions for the Monoid methods mempty and mappend

The generic defaults only work for types without alternatives (i.e. they have only one constructor). We cannot in general know how to deal with different constructors.

Synopsis

GMonoid type class

class GMonoid a where Source #

Methods

gmempty :: a Source #

Generic mempty

gmappend :: a -> a -> a Source #

Generic mappend

gmconcat :: [a] -> a Source #

Generic mconcat

gmempty :: (Generic a, GMonoid' (Rep a)) => a Source #

Generic mempty

gmappend :: (Generic a, GMonoid' (Rep a)) => a -> a -> a Source #

Generic mappend

Instances

GMonoid Ordering Source # 
GMonoid () Source # 

Methods

gmempty :: () Source #

gmappend :: () -> () -> () Source #

gmconcat :: [()] -> () Source #

GMonoid All Source # 
GMonoid Any Source # 
GMonoid [a] Source # 

Methods

gmempty :: [a] Source #

gmappend :: [a] -> [a] -> [a] Source #

gmconcat :: [[a]] -> [a] Source #

GMonoid a => GMonoid (Maybe a) Source # 

Methods

gmempty :: Maybe a Source #

gmappend :: Maybe a -> Maybe a -> Maybe a Source #

gmconcat :: [Maybe a] -> Maybe a Source #

GMonoid a => GMonoid (Identity a) Source # 
GMonoid m => GMonoid (WrappedMonoid m) Source # 
GMonoid a => GMonoid (Dual a) Source # 

Methods

gmempty :: Dual a Source #

gmappend :: Dual a -> Dual a -> Dual a Source #

gmconcat :: [Dual a] -> Dual a Source #

GMonoid (Endo a) Source # 

Methods

gmempty :: Endo a Source #

gmappend :: Endo a -> Endo a -> Endo a Source #

gmconcat :: [Endo a] -> Endo a Source #

Num a => GMonoid (Sum a) Source # 

Methods

gmempty :: Sum a Source #

gmappend :: Sum a -> Sum a -> Sum a Source #

gmconcat :: [Sum a] -> Sum a Source #

Num a => GMonoid (Product a) Source # 
GMonoid (First a) Source # 

Methods

gmempty :: First a Source #

gmappend :: First a -> First a -> First a Source #

gmconcat :: [First a] -> First a Source #

GMonoid (Last a) Source # 

Methods

gmempty :: Last a Source #

gmappend :: Last a -> Last a -> Last a Source #

gmconcat :: [Last a] -> Last a Source #

GMonoid b => GMonoid (a -> b) Source # 

Methods

gmempty :: a -> b Source #

gmappend :: (a -> b) -> (a -> b) -> a -> b Source #

gmconcat :: [a -> b] -> a -> b Source #

(GMonoid a, GMonoid b) => GMonoid (a, b) Source # 

Methods

gmempty :: (a, b) Source #

gmappend :: (a, b) -> (a, b) -> (a, b) Source #

gmconcat :: [(a, b)] -> (a, b) Source #

GMonoid (Proxy k s) Source # 

Methods

gmempty :: Proxy k s Source #

gmappend :: Proxy k s -> Proxy k s -> Proxy k s Source #

gmconcat :: [Proxy k s] -> Proxy k s Source #

(GMonoid a, GMonoid b, GMonoid c) => GMonoid (a, b, c) Source # 

Methods

gmempty :: (a, b, c) Source #

gmappend :: (a, b, c) -> (a, b, c) -> (a, b, c) Source #

gmconcat :: [(a, b, c)] -> (a, b, c) Source #

GMonoid a => GMonoid (Const k a b) Source # 

Methods

gmempty :: Const k a b Source #

gmappend :: Const k a b -> Const k a b -> Const k a b Source #

gmconcat :: [Const k a b] -> Const k a b Source #

Alternative f => GMonoid (Alt * f a) Source # 

Methods

gmempty :: Alt * f a Source #

gmappend :: Alt * f a -> Alt * f a -> Alt * f a Source #

gmconcat :: [Alt * f a] -> Alt * f a Source #

(GMonoid a, GMonoid b, GMonoid c, GMonoid d) => GMonoid (a, b, c, d) Source # 

Methods

gmempty :: (a, b, c, d) Source #

gmappend :: (a, b, c, d) -> (a, b, c, d) -> (a, b, c, d) Source #

gmconcat :: [(a, b, c, d)] -> (a, b, c, d) Source #

(GMonoid a, GMonoid b, GMonoid c, GMonoid d, GMonoid e) => GMonoid (a, b, c, d, e) Source # 

Methods

gmempty :: (a, b, c, d, e) Source #

gmappend :: (a, b, c, d, e) -> (a, b, c, d, e) -> (a, b, c, d, e) Source #

gmconcat :: [(a, b, c, d, e)] -> (a, b, c, d, e) Source #

(GMonoid a, GMonoid b, GMonoid c, GMonoid d, GMonoid e, GMonoid f) => GMonoid (a, b, c, d, e, f) Source # 

Methods

gmempty :: (a, b, c, d, e, f) Source #

gmappend :: (a, b, c, d, e, f) -> (a, b, c, d, e, f) -> (a, b, c, d, e, f) Source #

gmconcat :: [(a, b, c, d, e, f)] -> (a, b, c, d, e, f) Source #

(GMonoid a, GMonoid b, GMonoid c, GMonoid d, GMonoid e, GMonoid f, GMonoid g) => GMonoid (a, b, c, d, e, f, g) Source # 

Methods

gmempty :: (a, b, c, d, e, f, g) Source #

gmappend :: (a, b, c, d, e, f, g) -> (a, b, c, d, e, f, g) -> (a, b, c, d, e, f, g) Source #

gmconcat :: [(a, b, c, d, e, f, g)] -> (a, b, c, d, e, f, g) Source #

(GMonoid a, GMonoid b, GMonoid c, GMonoid d, GMonoid e, GMonoid f, GMonoid g, GMonoid h) => GMonoid (a, b, c, d, e, f, g, h) Source # 

Methods

gmempty :: (a, b, c, d, e, f, g, h) Source #

gmappend :: (a, b, c, d, e, f, g, h) -> (a, b, c, d, e, f, g, h) -> (a, b, c, d, e, f, g, h) Source #

gmconcat :: [(a, b, c, d, e, f, g, h)] -> (a, b, c, d, e, f, g, h) Source #

Default definitions

GMonoid

gmappenddefault :: (Generic a, GMonoid' (Rep a)) => a -> a -> a Source #

Internal auxiliary class for GMonoid

class GMonoid' f where Source #

Minimal complete definition

gmempty', gmappend'

Methods

gmempty' :: f x Source #

gmappend' :: f x -> f x -> f x Source #

Instances

GMonoid' * U1 Source # 

Methods

gmempty' :: f x Source #

gmappend' :: f x -> f x -> f x Source #

GMonoid a => GMonoid' * (K1 i a) Source # 

Methods

gmempty' :: f x Source #

gmappend' :: f x -> f x -> f x Source #

(GMonoid' * f, GMonoid' * h) => GMonoid' * ((:*:) f h) Source # 

Methods

gmempty' :: f x Source #

gmappend' :: f x -> f x -> f x Source #

GMonoid' * f => GMonoid' * (M1 i c f) Source # 

Methods

gmempty' :: f x Source #

gmappend' :: f x -> f x -> f x Source #

Monoid

These functions can be used in a Monoid instance. For example:

 -- LANGUAGE DeriveGeneric

 import Generics.Deriving.Base (Generic)
 import Generics.Deriving.Monoid

 data T a = C a (Maybe a) deriving Generic

 instance Monoid a => Monoid (T a) where
   mempty  = memptydefault
   mappend = mappenddefault
 

mappenddefault :: (Generic a, Monoid' (Rep a)) => a -> a -> a Source #

Internal auxiliary class for Monoid

class Monoid' f where Source #

Minimal complete definition

mempty', mappend'

Methods

mempty' :: f x Source #

mappend' :: f x -> f x -> f x Source #

Instances

Monoid' * U1 Source # 

Methods

mempty' :: f x Source #

mappend' :: f x -> f x -> f x Source #

Monoid a => Monoid' * (K1 i a) Source # 

Methods

mempty' :: f x Source #

mappend' :: f x -> f x -> f x Source #

(Monoid' * f, Monoid' * h) => Monoid' * ((:*:) f h) Source # 

Methods

mempty' :: f x Source #

mappend' :: f x -> f x -> f x Source #

Monoid' * f => Monoid' * (M1 i c f) Source # 

Methods

mempty' :: f x Source #

mappend' :: f x -> f x -> f x Source #

The Monoid module

This is exported for convenient access to the various wrapper types.