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 #

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) # | 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) #

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

toConstr :: Modular a -> Constr #

dataTypeOf :: Modular a -> DataType #

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

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

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

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

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

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

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

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

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

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

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

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-IhyDtHS7M7uHyZ7s7mY4S7" 'True) (C1 ('MetaCons "Modular" 'PrefixI 'True) (S1 ('MetaSel ('Just "getModular") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 a)))

Methods

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

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

Read a => Read (Modular a) # | Since: 0.7
Instance details Defined in Data.Ring.Ordered Methods readsPrec :: Int -> ReadS (Modular a) # readList :: ReadS [Modular a] # readPrec :: ReadPrec (Modular a) # readListPrec :: ReadPrec [Modular a] #
Show a => Show (Modular a) # | Since: 0.7
Instance details Defined in Data.Ring.Ordered Methods showsPrec :: Int -> Modular a -> ShowS # show :: Modular a -> String # showList :: [Modular a] -> ShowS #
Eq a => Eq (Modular a) # | Since: 0.7
Instance details Defined in Data.Ring.Ordered Methods (==) :: Modular a -> Modular a -> Bool # (/=) :: Modular a -> Modular a -> Bool #
Ord a => Ord (Modular a) # | Since: 0.7
Instance details Defined in Data.Ring.Ordered Methods compare :: Modular a -> Modular a -> Ordering # (<) :: Modular a -> Modular a -> Bool # (<=) :: Modular a -> Modular a -> Bool # (>) :: Modular a -> Modular a -> Bool # (>=) :: Modular a -> Modular a -> Bool # max :: Modular a -> Modular a -> Modular a # min :: Modular a -> Modular a -> Modular a #
OrderedRing (Modular Word16) # | Since: 0.7
Instance details Defined in Data.Ring.Ordered Methods abs :: Modular Word16 -> Modular Word16 # signum :: Modular Word16 -> Modular Word16 #
OrderedRing (Modular Word32) # | Since: 0.7
Instance details Defined in Data.Ring.Ordered Methods abs :: Modular Word32 -> Modular Word32 # signum :: Modular Word32 -> Modular Word32 #
OrderedRing (Modular Word64) # | Since: 0.7
Instance details Defined in Data.Ring.Ordered Methods abs :: Modular Word64 -> Modular Word64 # signum :: Modular Word64 -> Modular Word64 #
OrderedRing (Modular Word8) # | Since: 0.7
Instance details Defined in Data.Ring.Ordered Methods abs :: Modular Word8 -> Modular Word8 # signum :: Modular Word8 -> Modular Word8 #
OrderedRing (Modular Word) # | Since: 0.7
Instance details Defined in Data.Ring.Ordered Methods abs :: Modular Word -> Modular Word # signum :: Modular Word -> Modular Word #
Ring (Modular Word16) # |
Instance details Defined in Data.Ring.Ordered Methods negate :: Modular Word16 -> Modular Word16 #
Ring (Modular Word32) # |
Instance details Defined in Data.Ring.Ordered Methods negate :: Modular Word32 -> Modular Word32 #
Ring (Modular Word64) # |
Instance details Defined in Data.Ring.Ordered Methods negate :: Modular Word64 -> Modular Word64 #
Ring (Modular Word8) # |
Instance details Defined in Data.Ring.Ordered Methods negate :: Modular Word8 -> Modular Word8 #
Ring (Modular Word) # |
Instance details Defined in Data.Ring.Ordered Methods negate :: Modular Word -> Modular Word #
Semiring (Modular Word16) # |
Instance details Defined in Data.Ring.Ordered Methods plus :: Modular Word16 -> Modular Word16 -> Modular Word16 # zero :: Modular Word16 # times :: Modular Word16 -> Modular Word16 -> Modular Word16 # one :: Modular Word16 # fromNatural :: Natural -> Modular Word16 #
Semiring (Modular Word32) # |
Instance details Defined in Data.Ring.Ordered Methods plus :: Modular Word32 -> Modular Word32 -> Modular Word32 # zero :: Modular Word32 # times :: Modular Word32 -> Modular Word32 -> Modular Word32 # one :: Modular Word32 # fromNatural :: Natural -> Modular Word32 #
Semiring (Modular Word64) # |
Instance details Defined in Data.Ring.Ordered Methods plus :: Modular Word64 -> Modular Word64 -> Modular Word64 # zero :: Modular Word64 # times :: Modular Word64 -> Modular Word64 -> Modular Word64 # one :: Modular Word64 # fromNatural :: Natural -> Modular Word64 #
Semiring (Modular Word8) # |
Instance details Defined in Data.Ring.Ordered Methods plus :: Modular Word8 -> Modular Word8 -> Modular Word8 # zero :: Modular Word8 # times :: Modular Word8 -> Modular Word8 -> Modular Word8 # one :: Modular Word8 # fromNatural :: Natural -> Modular Word8 #
Semiring (Modular Word) # |
Instance details Defined in Data.Ring.Ordered Methods plus :: Modular Word -> Modular Word -> Modular Word # zero :: Modular Word # times :: Modular Word -> Modular Word -> Modular Word # one :: Modular Word # fromNatural :: Natural -> Modular Word #
type Rep (Modular a) # | Since: 0.7
Instance details Defined in Data.Ring.Ordered type Rep (Modular a) = D1 ('MetaData "Modular" "Data.Ring.Ordered" "semirings-0.7-IhyDtHS7M7uHyZ7s7mY4S7" '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 #

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 #

Compute the absolute value.

signum :: a -> a #

Determine the 'sign' of a value.

#### Instances

Instances details

OrderedRing Int16 # | Since: 0.7
Instance details Defined in Data.Ring.Ordered Methods abs :: Int16 -> Int16 # signum :: Int16 -> Int16 #
OrderedRing Int32 # | Since: 0.7
Instance details Defined in Data.Ring.Ordered Methods abs :: Int32 -> Int32 # signum :: Int32 -> Int32 #
OrderedRing Int64 # | Since: 0.7
Instance details Defined in Data.Ring.Ordered Methods abs :: Int64 -> Int64 # signum :: Int64 -> Int64 #
OrderedRing Int8 # | Since: 0.7
Instance details Defined in Data.Ring.Ordered Methods abs :: Int8 -> Int8 # signum :: Int8 -> Int8 #
OrderedRing Integer # | 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 # signum :: Integer -> Integer #
OrderedRing () # | 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 :: () -> () # signum :: () -> () #
OrderedRing Int # | Since: 0.7
Instance details Defined in Data.Ring.Ordered Methods abs :: Int -> Int # signum :: Int -> Int #
OrderedRing a => OrderedRing (Identity a) # | 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 # signum :: Identity a -> Identity a #
OrderedRing a => OrderedRing (Down a) # | 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 # signum :: Down a -> Down a #
OrderedRing a => OrderedRing (Dual a) # | 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 # signum :: Dual a -> Dual a #
Integral a => OrderedRing (Ratio a) # | 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 # signum :: Ratio a -> Ratio a #
OrderedRing (Modular Word16) # | Since: 0.7
Instance details Defined in Data.Ring.Ordered Methods abs :: Modular Word16 -> Modular Word16 # signum :: Modular Word16 -> Modular Word16 #
OrderedRing (Modular Word32) # | Since: 0.7
Instance details Defined in Data.Ring.Ordered Methods abs :: Modular Word32 -> Modular Word32 # signum :: Modular Word32 -> Modular Word32 #
OrderedRing (Modular Word64) # | Since: 0.7
Instance details Defined in Data.Ring.Ordered Methods abs :: Modular Word64 -> Modular Word64 # signum :: Modular Word64 -> Modular Word64 #
OrderedRing (Modular Word8) # | Since: 0.7
Instance details Defined in Data.Ring.Ordered Methods abs :: Modular Word8 -> Modular Word8 # signum :: Modular Word8 -> Modular Word8 #
OrderedRing (Modular Word) # | Since: 0.7
Instance details Defined in Data.Ring.Ordered Methods abs :: Modular Word -> Modular Word # signum :: Modular Word -> Modular Word #
HasResolution a => OrderedRing (Fixed a) # | Since: 0.7
Instance details Defined in Data.Ring.Ordered Methods abs :: Fixed a -> Fixed a # signum :: Fixed a -> Fixed a #
OrderedRing a => OrderedRing (Const a b) # | 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 # signum :: Const a b -> Const a b #