Generics.Deriving.Monoid

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

Safe Haskell | Safe
Language | Haskell2010

Generics.Deriving.Monoid

Contents

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

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

- class GMonoid a where
- gmemptydefault :: (Generic a, GMonoid' (Rep a)) => a
- gmappenddefault :: (Generic a, GMonoid' (Rep a)) => a -> a -> a
- class GMonoid' f where
- memptydefault :: (Generic a, Monoid' (Rep a)) => a
- mappenddefault :: (Generic a, Monoid' (Rep a)) => a -> a -> a
- class Monoid' f where
- module Data.Monoid

# GMonoid type class

class GMonoid a where #

Methods

gmempty :: a #

Generic `mempty`

gmappend :: a -> a -> a #

Generic `mappend`

gmconcat :: [a] -> a #

Generic `mconcat`

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

Generic `mempty`

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

Generic `mappend`

Instances

GMonoid Ordering # |
Methods gmempty :: Ordering # gmappend :: Ordering -> Ordering -> Ordering # gmconcat :: [Ordering] -> Ordering #
GMonoid () # |
Methods gmempty :: () # gmappend :: () -> () -> () # gmconcat :: [()] -> () #
GMonoid All # |
Methods gmempty :: All # gmappend :: All -> All -> All # gmconcat :: [All] -> All #
GMonoid Any # |
Methods gmempty :: Any # gmappend :: Any -> Any -> Any # gmconcat :: [Any] -> Any #
GMonoid [a] # |
Methods gmempty :: [a] # gmappend :: [a] -> [a] -> [a] # gmconcat :: [[a]] -> [a] #
GMonoid a => GMonoid (Maybe a) # |
Methods gmempty :: Maybe a # gmappend :: Maybe a -> Maybe a -> Maybe a # gmconcat :: [Maybe a] -> Maybe a #
GMonoid a => GMonoid (Identity a) # |
Methods gmempty :: Identity a # gmappend :: Identity a -> Identity a -> Identity a # gmconcat :: [Identity a] -> Identity a #
GMonoid m => GMonoid (WrappedMonoid m) # |
Methods gmempty :: WrappedMonoid m # gmappend :: WrappedMonoid m -> WrappedMonoid m -> WrappedMonoid m # gmconcat :: [WrappedMonoid m] -> WrappedMonoid m #
GMonoid a => GMonoid (Dual a) # |
Methods gmempty :: Dual a # gmappend :: Dual a -> Dual a -> Dual a # gmconcat :: [Dual a] -> Dual a #
GMonoid (Endo a) # |
Methods gmempty :: Endo a # gmappend :: Endo a -> Endo a -> Endo a # gmconcat :: [Endo a] -> Endo a #
Num a => GMonoid (Sum a) # |
Methods gmempty :: Sum a # gmappend :: Sum a -> Sum a -> Sum a # gmconcat :: [Sum a] -> Sum a #
Num a => GMonoid (Product a) # |
Methods gmempty :: Product a # gmappend :: Product a -> Product a -> Product a # gmconcat :: [Product a] -> Product a #
GMonoid (First a) # |
Methods gmempty :: First a # gmappend :: First a -> First a -> First a # gmconcat :: [First a] -> First a #
GMonoid (Last a) # |
Methods gmempty :: Last a # gmappend :: Last a -> Last a -> Last a # gmconcat :: [Last a] -> Last a #
GMonoid b => GMonoid (a -> b) # |
Methods gmempty :: a -> b # gmappend :: (a -> b) -> (a -> b) -> a -> b # gmconcat :: [a -> b] -> a -> b #
(GMonoid a, GMonoid b) => GMonoid (a, b) # |
Methods gmempty :: (a, b) # gmappend :: (a, b) -> (a, b) -> (a, b) # gmconcat :: [(a, b)] -> (a, b) #
GMonoid (Proxy k s) # |
Methods gmempty :: Proxy k s # gmappend :: Proxy k s -> Proxy k s -> Proxy k s # gmconcat :: [Proxy k s] -> Proxy k s #
(GMonoid a, GMonoid b, GMonoid c) => GMonoid (a, b, c) # |
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 (Const k a b) # |
Methods gmempty :: Const k a b # gmappend :: Const k a b -> Const k a b -> Const k a b # gmconcat :: [Const k a b] -> Const k a b #
Alternative f => GMonoid (Alt * f a) # |
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 d) => GMonoid (a, b, c, d) # |
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) # |
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) # |
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) # |
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) # |
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 GMonoid' f where #

Minimal complete definition

gmempty', gmappend'

Methods

gmempty' :: f x #

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

Instances

GMonoid' * U1 # |
Methods gmempty' :: f x # gmappend' :: f x -> f x -> f x #
GMonoid a => GMonoid' * (K1 i a) # |
Methods gmempty' :: f x # gmappend' :: f x -> f x -> f x #
(GMonoid' * f, GMonoid' * h) => GMonoid' * ((:*:) f h) # |
Methods gmempty' :: f x # gmappend' :: f x -> f x -> f x #
GMonoid' * f => GMonoid' * (M1 i c f) # |
Methods gmempty' :: f x # gmappend' :: f x -> f x -> 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 #

Minimal complete definition

mempty', mappend'

Methods

mempty' :: f x #

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

Instances

Monoid' * U1 # |
Methods mempty' :: f x # mappend' :: f x -> f x -> f x #
Monoid a => Monoid' * (K1 i a) # |
Methods mempty' :: f x # mappend' :: f x -> f x -> f x #
(Monoid' * f, Monoid' * h) => Monoid' * ((:*:) f h) # |
Methods mempty' :: f x # mappend' :: f x -> f x -> f x #
Monoid' * f => Monoid' * (M1 i c f) # |
Methods mempty' :: f x # mappend' :: f x -> f x -> f x #

# The Monoid module

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

module Data.Monoid