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

Safe Haskell | Safe
Language | Haskell2010

Generics.Deriving.Monoid

Contents

- Introduction
- GMonoid type class
- Default definitions
  - GMonoid
- Internal auxiliary class for GMonoid
  - Monoid
- Internal auxiliary class for Monoid
- The Monoid module
- Orphan instances

Synopsis

- class GSemigroup a => GMonoid a where
  - gmempty :: a
  - gmappend :: a -> a -> a
  - gmconcat :: [a] -> a
- gmemptydefault :: (Generic a, GMonoid' (Rep a)) => a
- gmappenddefault :: (Generic a, GMonoid' (Rep a)) => a -> a -> a
- class GSemigroup' f => GMonoid' f where
  - gmempty' :: f x
  - gmappend' :: f x -> f x -> f x
- memptydefault :: (Generic a, Monoid' (Rep a)) => a
- mappenddefault :: (Generic a, Monoid' (Rep a)) => a -> a -> a
- class Monoid' f where
  - mempty' :: f x
  - mappend' :: f x -> f x -> f x

# Introduction

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.

# GMonoid type class

class GSemigroup a => GMonoid a where #

Minimal complete definition

Nothing

Methods

gmempty :: a #

Generic `mempty`

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

gmappend :: a -> a -> a #

Generic `mappend`

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

gmconcat :: [a] -> a #

Generic `mconcat`

#### Instances

Instances details

GMonoid All # |
Instance details Defined in Generics.Deriving.Monoid.Internal Methods gmempty :: All # gmappend :: All -> All -> All # gmconcat :: [All] -> All #
GMonoid Any # |
Instance details Defined in Generics.Deriving.Monoid.Internal Methods gmempty :: Any # gmappend :: Any -> Any -> Any # gmconcat :: [Any] -> Any #
GMonoid Ordering # |
Instance details Defined in Generics.Deriving.Monoid.Internal Methods gmempty :: Ordering # gmappend :: Ordering -> Ordering -> Ordering # gmconcat :: [Ordering] -> Ordering #
GMonoid () # |
Instance details Defined in Generics.Deriving.Monoid.Internal Methods gmempty :: () # gmappend :: () -> () -> () # gmconcat :: [()] -> () #
GMonoid a => GMonoid (Identity a) # |
Instance details Defined in Generics.Deriving.Monoid.Internal Methods gmempty :: Identity a # gmappend :: Identity a -> Identity a -> Identity a # gmconcat :: [Identity a] -> Identity a #
GMonoid (First a) # |
Instance details Defined in Generics.Deriving.Monoid.Internal Methods gmempty :: First a # gmappend :: First a -> First a -> First a # gmconcat :: [First a] -> First a #
GMonoid (Last a) # |
Instance details Defined in Generics.Deriving.Monoid.Internal Methods gmempty :: Last a # gmappend :: Last a -> Last a -> Last a # gmconcat :: [Last a] -> Last a #
GMonoid a => GMonoid (Down a) # |
Instance details Defined in Generics.Deriving.Monoid.Internal Methods gmempty :: Down a # gmappend :: Down a -> Down a -> Down a # gmconcat :: [Down a] -> Down a #
GMonoid m => GMonoid (WrappedMonoid m) # |
Instance details Defined in Generics.Deriving.Monoid Methods gmempty :: WrappedMonoid m # gmappend :: WrappedMonoid m -> WrappedMonoid m -> WrappedMonoid m # gmconcat :: [WrappedMonoid m] -> WrappedMonoid m #
GMonoid a => GMonoid (Dual a) # |
Instance details Defined in Generics.Deriving.Monoid.Internal Methods gmempty :: Dual a # gmappend :: Dual a -> Dual a -> Dual a # gmconcat :: [Dual a] -> Dual a #
GMonoid (Endo a) # |
Instance details Defined in Generics.Deriving.Monoid.Internal Methods gmempty :: Endo a # gmappend :: Endo a -> Endo a -> Endo a # gmconcat :: [Endo a] -> Endo a #
Num a => GMonoid (Product a) # |
Instance details Defined in Generics.Deriving.Monoid.Internal Methods gmempty :: Product a # gmappend :: Product a -> Product a -> Product a # gmconcat :: [Product a] -> Product a #
Num a => GMonoid (Sum a) # |
Instance details Defined in Generics.Deriving.Monoid.Internal Methods gmempty :: Sum a # gmappend :: Sum a -> Sum a -> Sum a # gmconcat :: [Sum a] -> Sum a #
(Generic a, GMonoid' (Rep a)) => GMonoid (Default a) # |
Instance details Defined in Generics.Deriving.Default Methods gmempty :: Default a # gmappend :: Default a -> Default a -> Default a # gmconcat :: [Default a] -> Default a #
GSemigroup a => GMonoid (Maybe a) # |
Instance details Defined in Generics.Deriving.Monoid Methods gmempty :: Maybe a # gmappend :: Maybe a -> Maybe a -> Maybe a # gmconcat :: [Maybe a] -> Maybe a #
GMonoid [a] # |
Instance details Defined in Generics.Deriving.Monoid.Internal Methods gmempty :: [a] # gmappend :: [a] -> [a] -> [a] # gmconcat :: [[a]] -> [a] #
GMonoid (Proxy s) # |
Instance details Defined in Generics.Deriving.Monoid.Internal Methods gmempty :: Proxy s # gmappend :: Proxy s -> Proxy s -> Proxy s # gmconcat :: [Proxy s] -> Proxy s #
(GMonoid a, GMonoid b) => GMonoid (a, b) # |
Instance details Defined in Generics.Deriving.Monoid.Internal Methods gmempty :: (a, b) # gmappend :: (a, b) -> (a, b) -> (a, b) # gmconcat :: [(a, b)] -> (a, b) #
GMonoid b => GMonoid (a -> b) # |
Instance details Defined in Generics.Deriving.Monoid.Internal Methods gmempty :: a -> b # gmappend :: (a -> b) -> (a -> b) -> a -> b # gmconcat :: [a -> b] -> a -> b #
GMonoid a => GMonoid (Const a b) # |
Instance details Defined in Generics.Deriving.Monoid.Internal Methods gmempty :: Const a b # gmappend :: Const a b -> Const a b -> Const a b # gmconcat :: [Const a b] -> Const a b #
Alternative f => GMonoid (Alt f a) # |
Instance details Defined in Generics.Deriving.Monoid.Internal Methods gmempty :: Alt f a # gmappend :: Alt f a -> Alt f a -> Alt f a # gmconcat :: [Alt f a] -> Alt f a #
(GMonoid a, GMonoid b, GMonoid c) => GMonoid (a, b, c) # |
Instance details Defined in Generics.Deriving.Monoid.Internal Methods gmempty :: (a, b, c) # gmappend :: (a, b, c) -> (a, b, c) -> (a, b, c) # gmconcat :: [(a, b, c)] -> (a, b, c) #
(GMonoid a, GMonoid b, GMonoid c, GMonoid d) => GMonoid (a, b, c, d) # |
Instance details Defined in Generics.Deriving.Monoid.Internal Methods gmempty :: (a, b, c, d) # gmappend :: (a, b, c, d) -> (a, b, c, d) -> (a, b, c, d) # gmconcat :: [(a, b, c, d)] -> (a, b, c, d) #
(GMonoid a, GMonoid b, GMonoid c, GMonoid d, GMonoid e) => GMonoid (a, b, c, d, e) # |
Instance details Defined in Generics.Deriving.Monoid.Internal Methods gmempty :: (a, b, c, d, e) # gmappend :: (a, b, c, d, e) -> (a, b, c, d, e) -> (a, b, c, d, e) # gmconcat :: [(a, b, c, d, e)] -> (a, b, c, d, e) #
(GMonoid a, GMonoid b, GMonoid c, GMonoid d, GMonoid e, GMonoid f) => GMonoid (a, b, c, d, e, f) # |
Instance details Defined in Generics.Deriving.Monoid.Internal Methods gmempty :: (a, b, c, d, e, f) # gmappend :: (a, b, c, d, e, f) -> (a, b, c, d, e, f) -> (a, b, c, d, e, f) # gmconcat :: [(a, b, c, d, e, f)] -> (a, b, c, d, e, f) #
(GMonoid a, GMonoid b, GMonoid c, GMonoid d, GMonoid e, GMonoid f, GMonoid g) => GMonoid (a, b, c, d, e, f, g) # |
Instance details Defined in Generics.Deriving.Monoid.Internal Methods gmempty :: (a, b, c, d, e, f, g) # gmappend :: (a, b, c, d, e, f, g) -> (a, b, c, d, e, f, g) -> (a, b, c, d, e, f, g) # gmconcat :: [(a, b, c, d, e, f, g)] -> (a, b, c, d, e, f, g) #
(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) # |
Instance details Defined in Generics.Deriving.Monoid.Internal Methods gmempty :: (a, b, c, d, e, f, g, h) # 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) # gmconcat :: [(a, b, c, d, e, f, g, h)] -> (a, b, c, d, e, f, g, h) #

# Default definitions

## GMonoid

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

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

# Internal auxiliary class for GMonoid

class GSemigroup' f => GMonoid' f where #

Methods

gmempty' :: f x #

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

#### Instances

Instances details

GMonoid' (U1 :: k -> Type) # |
Instance details Defined in Generics.Deriving.Monoid.Internal Methods gmempty' :: forall (x :: k0). U1 x # gmappend' :: forall (x :: k0). U1 x -> U1 x -> U1 x #
(GMonoid' f, GMonoid' h) => GMonoid' (f :*: h :: k -> Type) # |
Instance details Defined in Generics.Deriving.Monoid.Internal Methods gmempty' :: forall (x :: k0). (f :*: h) x # gmappend' :: forall (x :: k0). (f :*: h) x -> (f :*: h) x -> (f :*: h) x #
GMonoid a => GMonoid' (K1 i a :: k -> Type) # |
Instance details Defined in Generics.Deriving.Monoid.Internal Methods gmempty' :: forall (x :: k0). K1 i a x # gmappend' :: forall (x :: k0). K1 i a x -> K1 i a x -> K1 i a x #
GMonoid' f => GMonoid' (M1 i c f :: k -> Type) # |
Instance details Defined in Generics.Deriving.Monoid.Internal Methods gmempty' :: forall (x :: k0). M1 i c f x # gmappend' :: forall (x :: k0). M1 i c f x -> M1 i c f x -> M1 i c f x #

## 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

memptydefault :: (Generic a, Monoid' (Rep a)) => a #

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

# Internal auxiliary class for Monoid

class Monoid' f where #

Methods

mempty' :: f x #

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

#### Instances

Instances details

Monoid' (U1 :: k -> Type) # |
Instance details Defined in Generics.Deriving.Monoid.Internal Methods mempty' :: forall (x :: k0). U1 x # mappend' :: forall (x :: k0). U1 x -> U1 x -> U1 x #
(Monoid' f, Monoid' h) => Monoid' (f :*: h :: k -> Type) # |
Instance details Defined in Generics.Deriving.Monoid.Internal Methods mempty' :: forall (x :: k0). (f :*: h) x # mappend' :: forall (x :: k0). (f :*: h) x -> (f :*: h) x -> (f :*: h) x #
Monoid a => Monoid' (K1 i a :: k -> Type) # |
Instance details Defined in Generics.Deriving.Monoid.Internal Methods mempty' :: forall (x :: k0). K1 i a x # mappend' :: forall (x :: k0). K1 i a x -> K1 i a x -> K1 i a x #
Monoid' f => Monoid' (M1 i c f :: k -> Type) # |
Instance details Defined in Generics.Deriving.Monoid.Internal Methods mempty' :: forall (x :: k0). M1 i c f x # mappend' :: forall (x :: k0). M1 i c f x -> M1 i c f x -> M1 i c f x #

# The Monoid module

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

# Orphan instances

GMonoid m => GMonoid (WrappedMonoid m) # |
Instance details Methods gmempty :: WrappedMonoid m # gmappend :: WrappedMonoid m -> WrappedMonoid m -> WrappedMonoid m # gmconcat :: [WrappedMonoid m] -> WrappedMonoid m #
GSemigroup a => GMonoid (Maybe a) # |
Instance details Methods gmempty :: Maybe a # gmappend :: Maybe a -> Maybe a -> Maybe a # gmconcat :: [Maybe a] -> Maybe a #