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

Copyright | (C) 2021 Koz Ross
License | BSD3
Maintainer | Koz Ross <koz.ross@retro-freedom.nz>
Stability | stable
Portability | GHC only
Safe Haskell | Trustworthy
Language | Haskell98

Data.Ring.Ordered

Contents

- Helper types
- Ordered ring type class

Description

An 'ordered ring' is a ring with a total order.

# Mathematical pedantry note

Many (if not most) of the instances of the `OrderedRing` type class are not truly ordered rings in the mathematical sense, as the axioms imply that the underlying set is either a singleton or infinite. Thus, the additional properties of ordered rings do not, in general, hold.

We indicate those instances that are 'truly' or 'mathematically' ordered rings in their documentation.

Synopsis

- newtype Modular a = Modular {
  - getModular :: a
  }
- class (Ring a, Ord a) => OrderedRing a where
  - abs :: a -> a
  - signum :: a -> a

# Helper types

newtype Modular a Source #

A wrapper to indicate the type is being treated as a modular arithmetic system whose modulus is the type's cardinality.

While we cannot guarantee that infinite types won't be wrapped by this, we only provide instances of the relevant type classes for those types we are certain are finite.

Since: 0.7

Constructors

Modular |

Fields

- getModular :: a

#### Instances

Instances details

Data a => Data (Modular a) Source # | Since: 0.7

Instance details

Defined in Data.Ring.Ordered

Methods

gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> Modular a -> c (Modular a) Source #

gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c (Modular a) Source #

toConstr :: Modular a -> Constr Source #

dataTypeOf :: Modular a -> DataType Source #

dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c (Modular a)) Source #

dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (Modular a)) Source #

gmapT :: (forall b. Data b => b -> b) -> Modular a -> Modular a Source #

gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Modular a -> r Source #

gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Modular a -> r Source #

gmapQ :: (forall d. Data d => d -> u) -> Modular a -> [u] Source #

gmapQi :: Int -> (forall d. Data d => d -> u) -> Modular a -> u Source #

gmapM :: Monad m => (forall d. Data d => d -> m d) -> Modular a -> m (Modular a) Source #

gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> Modular a -> m (Modular a) Source #

gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> Modular a -> m (Modular a) Source #

Bounded a => Bounded (Modular a) Source # | Since: 0.7
Instance details Defined in Data.Ring.Ordered Methods minBound :: Modular a Source # maxBound :: Modular a Source #
Generic (Modular a) Source # |

Instance details

Defined in Data.Ring.Ordered

Associated Types

type Rep (Modular a) | Since: semirings-0.7
Instance details Defined in Data.Ring.Ordered type Rep (Modular a) = D1 ('MetaData "Modular" "Data.Ring.Ordered" "semirings-0.7-GfH8CFjnoFgLT6ACdLwAYA" 'True) (C1 ('MetaCons "Modular" 'PrefixI 'True) (S1 ('MetaSel ('Just "getModular") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 a)))

Methods

from :: Modular a -> Rep (Modular a) x Source #

to :: Rep (Modular a) x -> Modular a Source #

Read a => Read (Modular a) Source # | Since: 0.7
Instance details Defined in Data.Ring.Ordered Methods readsPrec :: Int -> ReadS (Modular a) Source # readList :: ReadS [Modular a] Source # readPrec :: ReadPrec (Modular a) Source # readListPrec :: ReadPrec [Modular a] Source #
Show a => Show (Modular a) Source # | Since: 0.7
Instance details Defined in Data.Ring.Ordered Methods showsPrec :: Int -> Modular a -> ShowS Source # show :: Modular a -> String Source # showList :: [Modular a] -> ShowS Source #
Eq a => Eq (Modular a) Source # | Since: 0.7
Instance details Defined in Data.Ring.Ordered Methods (==) :: Modular a -> Modular a -> Bool Source # (/=) :: Modular a -> Modular a -> Bool Source #
Ord a => Ord (Modular a) Source # | Since: 0.7

Instance details

Defined in Data.Ring.Ordered

Methods

compare :: Modular a -> Modular a -> Ordering Source #

(<) :: Modular a -> Modular a -> Bool Source #

(<=) :: Modular a -> Modular a -> Bool Source #

(>) :: Modular a -> Modular a -> Bool Source #

(>=) :: Modular a -> Modular a -> Bool Source #

max :: Modular a -> Modular a -> Modular a Source #

min :: Modular a -> Modular a -> Modular a Source #

OrderedRing (Modular Word16) Source # | Since: 0.7
Instance details Defined in Data.Ring.Ordered Methods abs :: Modular Word16 -> Modular Word16 Source # signum :: Modular Word16 -> Modular Word16 Source #
OrderedRing (Modular Word32) Source # | Since: 0.7
Instance details Defined in Data.Ring.Ordered Methods abs :: Modular Word32 -> Modular Word32 Source # signum :: Modular Word32 -> Modular Word32 Source #
OrderedRing (Modular Word64) Source # | Since: 0.7
Instance details Defined in Data.Ring.Ordered Methods abs :: Modular Word64 -> Modular Word64 Source # signum :: Modular Word64 -> Modular Word64 Source #
OrderedRing (Modular Word8) Source # | Since: 0.7
Instance details Defined in Data.Ring.Ordered Methods abs :: Modular Word8 -> Modular Word8 Source # signum :: Modular Word8 -> Modular Word8 Source #
OrderedRing (Modular Word) Source # | Since: 0.7
Instance details Defined in Data.Ring.Ordered Methods abs :: Modular Word -> Modular Word Source # signum :: Modular Word -> Modular Word Source #
Ring (Modular Word16) Source # |
Instance details Defined in Data.Ring.Ordered Methods negate :: Modular Word16 -> Modular Word16 Source #
Ring (Modular Word32) Source # |
Instance details Defined in Data.Ring.Ordered Methods negate :: Modular Word32 -> Modular Word32 Source #
Ring (Modular Word64) Source # |
Instance details Defined in Data.Ring.Ordered Methods negate :: Modular Word64 -> Modular Word64 Source #
Ring (Modular Word8) Source # |
Instance details Defined in Data.Ring.Ordered Methods negate :: Modular Word8 -> Modular Word8 Source #
Ring (Modular Word) Source # |
Instance details Defined in Data.Ring.Ordered Methods negate :: Modular Word -> Modular Word Source #
Semiring (Modular Word16) Source # |
Instance details Defined in Data.Ring.Ordered Methods plus :: Modular Word16 -> Modular Word16 -> Modular Word16 Source # zero :: Modular Word16 Source # times :: Modular Word16 -> Modular Word16 -> Modular Word16 Source # one :: Modular Word16 Source # fromNatural :: Natural -> Modular Word16 Source #
Semiring (Modular Word32) Source # |
Instance details Defined in Data.Ring.Ordered Methods plus :: Modular Word32 -> Modular Word32 -> Modular Word32 Source # zero :: Modular Word32 Source # times :: Modular Word32 -> Modular Word32 -> Modular Word32 Source # one :: Modular Word32 Source # fromNatural :: Natural -> Modular Word32 Source #
Semiring (Modular Word64) Source # |
Instance details Defined in Data.Ring.Ordered Methods plus :: Modular Word64 -> Modular Word64 -> Modular Word64 Source # zero :: Modular Word64 Source # times :: Modular Word64 -> Modular Word64 -> Modular Word64 Source # one :: Modular Word64 Source # fromNatural :: Natural -> Modular Word64 Source #
Semiring (Modular Word8) Source # |
Instance details Defined in Data.Ring.Ordered Methods plus :: Modular Word8 -> Modular Word8 -> Modular Word8 Source # zero :: Modular Word8 Source # times :: Modular Word8 -> Modular Word8 -> Modular Word8 Source # one :: Modular Word8 Source # fromNatural :: Natural -> Modular Word8 Source #
Semiring (Modular Word) Source # |
Instance details Defined in Data.Ring.Ordered Methods plus :: Modular Word -> Modular Word -> Modular Word Source # zero :: Modular Word Source # times :: Modular Word -> Modular Word -> Modular Word Source # one :: Modular Word Source # fromNatural :: Natural -> Modular Word Source #
type Rep (Modular a) Source # | Since: 0.7
Instance details Defined in Data.Ring.Ordered type Rep (Modular a) = D1 ('MetaData "Modular" "Data.Ring.Ordered" "semirings-0.7-GfH8CFjnoFgLT6ACdLwAYA" 'True) (C1 ('MetaCons "Modular" 'PrefixI 'True) (S1 ('MetaSel ('Just "getModular") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 a)))

# Ordered ring type class

class (Ring a, Ord a) => OrderedRing a where Source #

The class of rings which also have a total order.

Instance should satisfy the following laws:

-     abs zero = zero

-     abs x = abs (negate x)

-     x - abs x = zero

-     signum zero = zero

- If `x `>` `zero``, then ``signum` x = `one``
- If `x `<` `zero``, then ``signum` x = `negate` `one``

Since: 0.7

Methods

abs :: a -> a Source #

Compute the absolute value.

signum :: a -> a Source #

Determine the 'sign' of a value.

#### Instances

Instances details

OrderedRing Int16 Source # | Since: 0.7
Instance details Defined in Data.Ring.Ordered Methods abs :: Int16 -> Int16 Source # signum :: Int16 -> Int16 Source #
OrderedRing Int32 Source # | Since: 0.7
Instance details Defined in Data.Ring.Ordered Methods abs :: Int32 -> Int32 Source # signum :: Int32 -> Int32 Source #
OrderedRing Int64 Source # | Since: 0.7
Instance details Defined in Data.Ring.Ordered Methods abs :: Int64 -> Int64 Source # signum :: Int64 -> Int64 Source #
OrderedRing Int8 Source # | Since: 0.7
Instance details Defined in Data.Ring.Ordered Methods abs :: Int8 -> Int8 Source # signum :: Int8 -> Int8 Source #
OrderedRing Integer Source # | This instance is a 'true' or 'mathematical' ordered ring, as `Integer` is an infinite type. Since: 0.7
Instance details Defined in Data.Ring.Ordered Methods abs :: Integer -> Integer Source # signum :: Integer -> Integer Source #
OrderedRing () Source # | This instance is a 'true' or 'mathematical' ordered ring, as it is a singleton. We assume that `()` has a zero signum. Since: 0.7
Instance details Defined in Data.Ring.Ordered Methods abs :: () -> () Source # signum :: () -> () Source #
OrderedRing Int Source # | Since: 0.7
Instance details Defined in Data.Ring.Ordered Methods abs :: Int -> Int Source # signum :: Int -> Int Source #
OrderedRing a => OrderedRing (Identity a) Source # | Where `a` is a 'true' or 'mathematical' ordered ring, so is this. Since: 0.7
Instance details Defined in Data.Ring.Ordered Methods abs :: Identity a -> Identity a Source # signum :: Identity a -> Identity a Source #
OrderedRing a => OrderedRing (Down a) Source # | Where `a` is a 'true' or 'mathematical' ordered ring, so is this. Since: 0.7
Instance details Defined in Data.Ring.Ordered Methods abs :: Down a -> Down a Source # signum :: Down a -> Down a Source #
OrderedRing a => OrderedRing (Dual a) Source # | Where `a` is a 'true' or 'mathematical' ordered ring, so is this. Since: 0.7
Instance details Defined in Data.Ring.Ordered Methods abs :: Dual a -> Dual a Source # signum :: Dual a -> Dual a Source #
Integral a => OrderedRing (Ratio a) Source # | Where `a ~ `Integer``, this instance is a 'true' or 'mathematical' ordered ring, as the resulting type is infinite. Since: 0.7
Instance details Defined in Data.Ring.Ordered Methods abs :: Ratio a -> Ratio a Source # signum :: Ratio a -> Ratio a Source #
OrderedRing (Modular Word16) Source # | Since: 0.7
Instance details Defined in Data.Ring.Ordered Methods abs :: Modular Word16 -> Modular Word16 Source # signum :: Modular Word16 -> Modular Word16 Source #
OrderedRing (Modular Word32) Source # | Since: 0.7
Instance details Defined in Data.Ring.Ordered Methods abs :: Modular Word32 -> Modular Word32 Source # signum :: Modular Word32 -> Modular Word32 Source #
OrderedRing (Modular Word64) Source # | Since: 0.7
Instance details Defined in Data.Ring.Ordered Methods abs :: Modular Word64 -> Modular Word64 Source # signum :: Modular Word64 -> Modular Word64 Source #
OrderedRing (Modular Word8) Source # | Since: 0.7
Instance details Defined in Data.Ring.Ordered Methods abs :: Modular Word8 -> Modular Word8 Source # signum :: Modular Word8 -> Modular Word8 Source #
OrderedRing (Modular Word) Source # | Since: 0.7
Instance details Defined in Data.Ring.Ordered Methods abs :: Modular Word -> Modular Word Source # signum :: Modular Word -> Modular Word Source #
HasResolution a => OrderedRing (Fixed a) Source # | Since: 0.7
Instance details Defined in Data.Ring.Ordered Methods abs :: Fixed a -> Fixed a Source # signum :: Fixed a -> Fixed a Source #
OrderedRing a => OrderedRing (Const a b) Source # | Where `a` is a 'true' or 'mathematical' ordered ring, so is this. Since: 0.7
Instance details Defined in Data.Ring.Ordered Methods abs :: Const a b -> Const a b Source # signum :: Const a b -> Const a b Source #