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

Safe Haskell | None
Language | Haskell98

Generics.Deriving.Monoid

Contents

- GMonoid type class
- Default definitions
  - GMonoid
  - 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
  - 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
- memptydefault :: (Generic a, Monoid' (Rep a)) => a
- mappenddefault :: (Generic a, Monoid' (Rep a)) => a -> a -> a
- module Data.Monoid

# GMonoid type class

class GMonoid a where Source

Minimal complete definition

Nothing

Methods

gmempty :: a Source

Generic `mempty`

gmappend :: a -> a -> a Source

Generic `mappend`

gmconcat :: [a] -> a Source

Generic `mconcat`

Instances

GMonoid Ordering Source |
GMonoid () Source |
GMonoid All Source |
GMonoid Any Source |
GMonoid [a] Source |
GMonoid a => GMonoid (Identity a) Source |
GMonoid a => GMonoid (Dual a) Source |
GMonoid (Endo a) Source |
Num a => GMonoid (Sum a) Source |
Num a => GMonoid (Product a) Source |
GMonoid (First a) Source |
GMonoid (Last a) Source |
GMonoid a => GMonoid (Maybe a) Source |
GMonoid b => GMonoid (a -> b) Source |
(GMonoid a, GMonoid b) => GMonoid (a, b) Source |
GMonoid a => GMonoid (Const a b) Source |
GMonoid (Proxy * s) Source |
(GMonoid a, GMonoid b, GMonoid c) => GMonoid (a, b, c) Source |
(GMonoid a, GMonoid b, GMonoid c, GMonoid d) => GMonoid (a, b, c, d) Source |
(GMonoid a, GMonoid b, GMonoid c, GMonoid d, GMonoid e) => GMonoid (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 |
(GMonoid a, GMonoid b, GMonoid c, GMonoid d, GMonoid e, GMonoid f, GMonoid g) => GMonoid (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 |

# Default definitions

## GMonoid

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

gmappenddefault :: (Generic a, GMonoid' (Rep a)) => a -> a -> a 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

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

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

# The Monoid module

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

module Data.Monoid