semirings-0.6: two monoids as one, in holy haskimony

Copyright | (C) 2018 chessai
License | MIT (see the file LICENSE)
Maintainer | chessai <chessai1996@gmail.com>
Stability | provisional
Portability | portable
Safe Haskell | Safe-Inferred
Language | Haskell98

Data.Semiring.Generic

Contents

- Orphan instances

Description

This module provides generic deriving tools for semirings and rings for product-like structures.

Synopsis

- class GSemiring f where
  - gzero' :: f a
  - gone' :: f a
  - gplus' :: f a -> f a -> f a
  - gtimes' :: f a -> f a -> f a
  - gfromNatural' :: Natural -> f a
- gzero :: (Generic a, GSemiring (Rep a)) => a
- gone :: (Generic a, GSemiring (Rep a)) => a
- gplus :: (Generic a, GSemiring (Rep a)) => a -> a -> a
- gtimes :: (Generic a, GSemiring (Rep a)) => a -> a -> a
- gfromNatural :: (Generic a, GSemiring (Rep a)) => Natural -> a
- class GRing f where
  - gnegate' :: f a -> f a
- gnegate :: (Generic a, GRing (Rep a)) => a -> a
- newtype GenericSemiring a = GenericSemiring a

# Documentation

class GSemiring f where Source #

Generic `Semiring` class, used to implement `plus`, `times`, `zero`, and `one` for product-like types implementing `Generic`.

Methods

gzero' :: f a Source #

gone' :: f a Source #

gplus' :: f a -> f a -> f a Source #

gtimes' :: f a -> f a -> f a Source #

gfromNatural' :: Natural -> f a Source #

#### Instances

Instances details

GSemiring (U1 :: Type -> Type) Source # |
Instance details Defined in Data.Semiring.Generic Methods gzero' :: U1 a Source # gone' :: U1 a Source # gplus' :: U1 a -> U1 a -> U1 a Source # gtimes' :: U1 a -> U1 a -> U1 a Source # gfromNatural' :: Natural -> U1 a Source #
(GSemiring a, GSemiring b) => GSemiring (a :*: b) Source # |
Instance details Defined in Data.Semiring.Generic Methods gzero' :: (a :*: b) a0 Source # gone' :: (a :*: b) a0 Source # gplus' :: (a :*: b) a0 -> (a :*: b) a0 -> (a :*: b) a0 Source # gtimes' :: (a :*: b) a0 -> (a :*: b) a0 -> (a :*: b) a0 Source # gfromNatural' :: Natural -> (a :*: b) a0 Source #
Semiring a => GSemiring (K1 i a :: Type -> Type) Source # |
Instance details Defined in Data.Semiring.Generic Methods gzero' :: K1 i a a0 Source # gone' :: K1 i a a0 Source # gplus' :: K1 i a a0 -> K1 i a a0 -> K1 i a a0 Source # gtimes' :: K1 i a a0 -> K1 i a a0 -> K1 i a a0 Source # gfromNatural' :: Natural -> K1 i a a0 Source #
GSemiring a => GSemiring (M1 i c a) Source # |
Instance details Defined in Data.Semiring.Generic Methods gzero' :: M1 i c a a0 Source # gone' :: M1 i c a a0 Source # gplus' :: M1 i c a a0 -> M1 i c a a0 -> M1 i c a a0 Source # gtimes' :: M1 i c a a0 -> M1 i c a a0 -> M1 i c a a0 Source # gfromNatural' :: Natural -> M1 i c a a0 Source #

gzero :: (Generic a, GSemiring (Rep a)) => a Source #

Generically generate a `Semiring` `zero` for any product-like type implementing `Generic`.

It is only defined for product types.

    gplus gzero a = a = gplus a gzero

gone :: (Generic a, GSemiring (Rep a)) => a Source #

Generically generate a `Semiring` `one` for any product-like type implementing `Generic`.

It is only defined for product types.

    gtimes gone a = a = gtimes a gone

gplus :: (Generic a, GSemiring (Rep a)) => a -> a -> a Source #

Generically generate a `Semiring` `plus` operation for any type implementing `Generic`. It is only defined for product types.

    gplus a b = gplus b a

gtimes :: (Generic a, GSemiring (Rep a)) => a -> a -> a Source #

Generically generate a `Semiring` `times` operation for any type implementing `Generic`. It is only defined for product types.

    gtimes a (gtimes b c) = gtimes (gtimes a b) c
    gtimes a gzero = gzero = gtimes gzero a

gfromNatural :: (Generic a, GSemiring (Rep a)) => Natural -> a Source #

Generically generate a `Semiring` `fromNatural` for any product-like type implementing `Generic`.

It is only defined for product types.

class GRing f where Source #

Generic `Ring` class, used to implement `negate` for product-like types implementing `Generic`.

Methods

gnegate' :: f a -> f a Source #

#### Instances

Instances details

GRing (U1 :: Type -> Type) Source # |
Instance details Defined in Data.Semiring.Generic Methods gnegate' :: U1 a -> U1 a Source #
(GRing a, GRing b) => GRing (a :*: b) Source # |
Instance details Defined in Data.Semiring.Generic Methods gnegate' :: (a :*: b) a0 -> (a :*: b) a0 Source #
Ring a => GRing (K1 i a :: Type -> Type) Source # |
Instance details Defined in Data.Semiring.Generic Methods gnegate' :: K1 i a a0 -> K1 i a a0 Source #
GRing a => GRing (M1 i c a) Source # |
Instance details Defined in Data.Semiring.Generic Methods gnegate' :: M1 i c a a0 -> M1 i c a a0 Source #

gnegate :: (Generic a, GRing (Rep a)) => a -> a Source #

Generically generate a `Ring` `negate` operation for any type implementing `Generic`. It is only defined for product types.

    gplus a (gnegate a) = zero

newtype GenericSemiring a Source #

An Identity-style wrapper with a `Generic` interface to be used with '-XDerivingVia'.

Constructors

GenericSemiring a |

#### Instances

Instances details

(Generic a, GSemiring (Rep a)) => Semiring (GenericSemiring a) Source # |
Instance details Defined in Data.Semiring.Generic Methods plus :: GenericSemiring a -> GenericSemiring a -> GenericSemiring a Source # zero :: GenericSemiring a Source # times :: GenericSemiring a -> GenericSemiring a -> GenericSemiring a Source # one :: GenericSemiring a Source # fromNatural :: Natural -> GenericSemiring a Source #

# Orphan instances

(Ring a, Ring b) => Ring (a, b) Source # |
Instance details Methods negate :: (a, b) -> (a, b) Source #
(Semiring a, Semiring b) => Semiring (a, b) Source # |
Instance details Methods plus :: (a, b) -> (a, b) -> (a, b) Source # zero :: (a, b) Source # times :: (a, b) -> (a, b) -> (a, b) Source # one :: (a, b) Source # fromNatural :: Natural -> (a, b) Source #
(Ring a, Ring b, Ring c) => Ring (a, b, c) Source # |
Instance details Methods negate :: (a, b, c) -> (a, b, c) Source #
(Semiring a, Semiring b, Semiring c) => Semiring (a, b, c) Source # |
Instance details Methods plus :: (a, b, c) -> (a, b, c) -> (a, b, c) Source # zero :: (a, b, c) Source # times :: (a, b, c) -> (a, b, c) -> (a, b, c) Source # one :: (a, b, c) Source # fromNatural :: Natural -> (a, b, c) Source #
(Ring a, Ring b, Ring c, Ring d) => Ring (a, b, c, d) Source # |
Instance details Methods negate :: (a, b, c, d) -> (a, b, c, d) Source #
(Semiring a, Semiring b, Semiring c, Semiring d) => Semiring (a, b, c, d) Source # |
Instance details Methods plus :: (a, b, c, d) -> (a, b, c, d) -> (a, b, c, d) Source # zero :: (a, b, c, d) Source # times :: (a, b, c, d) -> (a, b, c, d) -> (a, b, c, d) Source # one :: (a, b, c, d) Source # fromNatural :: Natural -> (a, b, c, d) Source #
(Ring a, Ring b, Ring c, Ring d, Ring e) => Ring (a, b, c, d, e) Source # |
Instance details Methods negate :: (a, b, c, d, e) -> (a, b, c, d, e) Source #
(Semiring a, Semiring b, Semiring c, Semiring d, Semiring e) => Semiring (a, b, c, d, e) Source # |
Instance details Methods plus :: (a, b, c, d, e) -> (a, b, c, d, e) -> (a, b, c, d, e) Source # zero :: (a, b, c, d, e) Source # times :: (a, b, c, d, e) -> (a, b, c, d, e) -> (a, b, c, d, e) Source # one :: (a, b, c, d, e) Source # fromNatural :: Natural -> (a, b, c, d, e) Source #
(Ring a, Ring b, Ring c, Ring d, Ring e, Ring f) => Ring (a, b, c, d, e, f) Source # |
Instance details Methods negate :: (a, b, c, d, e, f) -> (a, b, c, d, e, f) Source #
(Semiring a, Semiring b, Semiring c, Semiring d, Semiring e, Semiring f) => Semiring (a, b, c, d, e, f) Source # |
Instance details Methods plus :: (a, b, c, d, e, f) -> (a, b, c, d, e, f) -> (a, b, c, d, e, f) Source # zero :: (a, b, c, d, e, f) Source # times :: (a, b, c, d, e, f) -> (a, b, c, d, e, f) -> (a, b, c, d, e, f) Source # one :: (a, b, c, d, e, f) Source # fromNatural :: Natural -> (a, b, c, d, e, f) Source #
(Ring a, Ring b, Ring c, Ring d, Ring e, Ring f, Ring g) => Ring (a, b, c, d, e, f, g) Source # |
Instance details Methods negate :: (a, b, c, d, e, f, g) -> (a, b, c, d, e, f, g) Source #
(Semiring a, Semiring b, Semiring c, Semiring d, Semiring e, Semiring f, Semiring g) => Semiring (a, b, c, d, e, f, g) Source # |
Instance details Methods plus :: (a, b, c, d, e, f, g) -> (a, b, c, d, e, f, g) -> (a, b, c, d, e, f, g) Source # zero :: (a, b, c, d, e, f, g) Source # times :: (a, b, c, d, e, f, g) -> (a, b, c, d, e, f, g) -> (a, b, c, d, e, f, g) Source # one :: (a, b, c, d, e, f, g) Source # fromNatural :: Natural -> (a, b, c, d, e, f, g) Source #