semirings-0.7: 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 | None
Language | Haskell98

Data.Semiring.Generic

Description

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

Synopsis

- class GSemiring (f :: Type -> Type) 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 :: Type -> Type) where
  - gnegate' :: f a -> f a
- gnegate :: (Generic a, GRing (Rep a)) => a -> a
- newtype GenericSemiring a = GenericSemiring a

# Documentation

class GSemiring (f :: Type -> Type) where #

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

Methods

gzero' :: f a #

gone' :: f a #

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

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

gfromNatural' :: Natural -> f a #

#### Instances

Instances details

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

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

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 #

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 #

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 #

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 #

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

It is only defined for product types.

class GRing (f :: Type -> Type) where #

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

Methods

gnegate' :: f a -> f a #

#### Instances

Instances details

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

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

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 #

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) # |
Instance details Defined in Data.Semiring.Generic Methods plus :: GenericSemiring a -> GenericSemiring a -> GenericSemiring a # zero :: GenericSemiring a # times :: GenericSemiring a -> GenericSemiring a -> GenericSemiring a # one :: GenericSemiring a # fromNatural :: Natural -> GenericSemiring a #