{-# LANGUAGE BangPatterns               #-}
{-# LANGUAGE CPP                        #-}
{-# LANGUAGE DeriveDataTypeable         #-}
{-# LANGUAGE DeriveFoldable             #-}
{-# LANGUAGE DeriveFunctor              #-}
{-# LANGUAGE DeriveGeneric              #-}
{-# LANGUAGE DeriveTraversable          #-}
{-# LANGUAGE FlexibleContexts           #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE NoImplicitPrelude          #-}
{-# LANGUAGE Rank2Types                 #-}
{-# LANGUAGE ScopedTypeVariables        #-}
{-# LANGUAGE StandaloneDeriving         #-}
#if MIN_VERSION_base(4,12,0)
{-# LANGUAGE DerivingVia                #-}
#else
{-# LANGUAGE TemplateHaskell            #-}
#endif

-----------------------------------------------------------------------------
-- |
-- A class for semirings (types with two binary operations, one commutative and one associative, and two respective identities), with various general-purpose instances.
--
-----------------------------------------------------------------------------

module Data.Semiring
  ( -- * Semiring typeclass
    Semiring(..)
  , (+)
  , (*)
  , (^)
  , foldMapP
  , foldMapT
  , sum
  , product
  , sum'
  , product'
  , isZero
  , isOne

    -- * Types
  , Add(..)
  , Mul(..)
  , WrappedNum(..)
  , Mod2(..)
#if defined(VERSION_containers)
  , IntSetOf(..)
  , IntMapOf(..)
#endif

    -- * Ring typeclass
  , Ring(..)
  , fromInteger
  , fromIntegral
  , minus
  , (-)
  ) where

import           Control.Applicative (Applicative(..), Const(..), liftA2)
import           Data.Bits (Bits (xor))
import           Data.Bool (Bool(..), (||), (&&), otherwise)
import           Data.Coerce (Coercible, coerce)
import           Data.Complex (Complex(..))
import           Data.Eq (Eq(..))
import           Data.Fixed (Fixed, HasResolution)
import           Data.Foldable (Foldable(foldMap))
import qualified Data.Foldable as Foldable
import           Data.Function ((.), const, id)
#if defined(VERSION_unordered_containers) || defined(VERSION_containers)
import           Data.Function (flip)
#endif
import           Data.Functor (Functor(..))
#if MIN_VERSION_base(4,12,0)
import           Data.Functor.Contravariant (Predicate(..), Equivalence(..), Op(..))
#endif
import           Data.Functor.Identity (Identity(..))
#if defined(VERSION_unordered_containers)
import           Data.Hashable (Hashable)
import           Data.HashMap.Strict (HashMap)
import qualified Data.HashMap.Strict as HashMap
import           Data.HashSet (HashSet)
import qualified Data.HashSet as HashSet
#endif
import           Data.Int (Int, Int8, Int16, Int32, Int64)
import           Data.Maybe (Maybe(..))
#if MIN_VERSION_base(4,12,0)
import           Data.Monoid (Ap(..))
#endif
#if defined(VERSION_containers)
import           Data.IntMap (IntMap)
import qualified Data.IntMap as IntMap
import           Data.IntSet (IntSet)
import qualified Data.IntSet as IntSet
import           Data.Map (Map)
import qualified Data.Map as Map
#endif
import           Data.Monoid (Monoid(..), Dual(..))
import           Data.Ord (Ord((<)), (>=))
import           Data.Ord (Down(..))
import           Data.Proxy (Proxy(..))
import           Data.Ratio (Ratio, Rational, (%))
import           Data.Semigroup (Semigroup ((<>), stimes))
#if defined(VERSION_containers)
import           Data.Set (Set)
import qualified Data.Set as Set
#endif
import           Data.Traversable (Traversable)
import           Data.Typeable (Typeable)
import           Data.Word (Word, Word8, Word16, Word32, Word64)
import           Foreign.C.Types
  (CChar, CClock, CDouble, CFloat, CInt,
   CIntMax, CIntPtr, CLLong, CLong,
   CPtrdiff, CSChar, CSUSeconds, CShort,
   CSigAtomic, CSize, CTime, CUChar, CUInt,
   CUIntMax, CUIntPtr, CULLong, CULong,
   CUSeconds, CUShort, CWchar)
import           Foreign.Ptr (IntPtr, WordPtr)
import           Foreign.Storable (Storable)
import           GHC.Enum (Enum, Bounded)
import           GHC.Err (error)
import           GHC.Float (Float, Double)
import           GHC.Generics (Generic,Generic1)
import           GHC.IO (IO)
import qualified GHC.Num as Num
import           GHC.Read (Read)
import           GHC.Real (Integral, Fractional, Real, RealFrac)
import qualified GHC.Real as Real
import           GHC.Show (Show)
import           Numeric.Natural (Natural)
import           Prelude (Integer, Ordering(..), compare, even, quot)

#if !MIN_VERSION_base(4,12,0)
import           Language.Haskell.TH.Syntax (Q, Dec, Type)
import qualified Prelude as P
#endif

#include "HsBaseConfig.h"
import           System.Posix.Types (
#ifdef HTYPE_CC_T
                 CCc(..),
#endif
#ifdef HTYPE_DEV_T
                 CDev(..),
#endif
#ifdef HTYPE_GID_T
                 CGid(..),
#endif
#ifdef HTYPE_INO_T
                 CIno(..),
#endif
#ifdef HTYPE_MODE_T
                 CMode(..),
#endif
#ifdef HTYPE_NLINK_T
                 CNlink(..),
#endif
#ifdef HTYPE_OFF_T
                 COff(..),
#endif
#ifdef HTYPE_PID_T
                 CPid(..),
#endif
#ifdef HTYPE_RLIM_T
                 CRLim(..),
#endif
#ifdef HTYPE_SPEED_T
                 CSpeed(..),
#endif
#ifdef HTYPE_SSIZE_T
                 CSsize(..),
#endif
#ifdef HTYPE_TCFLAG_T
                 CTcflag(..),
#endif
#ifdef HTYPE_UID_T
                 CUid(..),
#endif
                 Fd(..))

infixl 7 *, `times`
infixl 6 +, `plus`, -, `minus`
infixr 8 ^

{--------------------------------------------------------------------
  Helpers
--------------------------------------------------------------------}

-- | Raise a number to a non-negative integral power.
-- If the power is negative, this will call 'error'.
{-# SPECIALISE [1] (^) ::
        Integer -> Integer -> Integer,
        Integer -> Int -> Integer,
        Int -> Int -> Int #-}
{-# INLINABLE [1] (^) #-} -- See note [Inlining (^)]
(^) :: (Semiring a, Integral b) => a -> b -> a
a
x ^ :: forall a b. (Semiring a, Integral b) => a -> b -> a
^ b
y
  | b
y b -> b -> Bool
forall a. Ord a => a -> a -> Bool
< b
0 = [Char] -> a
forall a. HasCallStack => [Char] -> a
error [Char]
"Data.Semiring.^: negative power"
  | b
y b -> b -> Bool
forall a. Eq a => a -> a -> Bool
== b
0 = a
forall a. Semiring a => a
one
  | Bool
otherwise = Mul a -> a
forall a. Mul a -> a
getMul (b -> Mul a -> Mul a
forall b. Integral b => b -> Mul a -> Mul a
forall a b. (Semigroup a, Integral b) => b -> a -> a
stimes b
y (a -> Mul a
forall a. a -> Mul a
Mul a
x))

{- Note [Inlining (^)]
   ~~~~~~~~~~~~~~~~~~~
   The INLINABLE pragma allows (^) to be specialised at its call sites.
   If it is called repeatedly at the same type, that can make a huge
   difference, because of those constants which can be repeatedly
   calculated.

   Currently the fromInteger calls are not floated because we get
             \d1 d2 x y -> blah
   after the gentle round of simplification.
-}

{- Rules for powers with known small exponent
    see Trac #5237
    For small exponents, (^) is inefficient compared to manually
    expanding the multiplication tree.
    Here, rules for the most common exponent types are given.
    The range of exponents for which rules are given is quite
    arbitrary and kept small to not unduly increase the number of rules.
    It might be desirable to have corresponding rules also for
    exponents of other types (e.g., Word), but it's doubtful they
    would fire, since the exponents of other types tend to get
    floated out before the rule has a chance to fire. (Why?)

    Note: Trying to save multiplication by sharing the square for
    exponents 4 and 5 does not save time, indeed, for Double, it is
    up to twice slower, so the rules contain flat sequences of
    multiplications.
-}

{-# RULES
"^0/Int" forall x. x ^ (0 :: Int) = one
"^1/Int" forall x. x ^ (1 :: Int) = let u = x in u
"^2/Int" forall x. x ^ (2 :: Int) = let u = x in u*u
"^3/Int" forall x. x ^ (3 :: Int) = let u = x in u*u*u
"^4/Int" forall x. x ^ (4 :: Int) = let u = x in u*u*u*u
"^5/Int" forall x. x ^ (5 :: Int) = let u = x in u*u*u*u*u
"^0/Integer" forall x. x ^ (0 :: Integer) = one
"^1/Integer" forall x. x ^ (1 :: Integer) = let u = x in u
"^2/Integer" forall x. x ^ (2 :: Integer) = let u = x in u*u
"^3/Integer" forall x. x ^ (3 :: Integer) = let u = x in u*u*u
"^4/Integer" forall x. x ^ (4 :: Integer) = let u = x in u*u*u*u
"^5/Integer" forall x. x ^ (5 :: Integer) = let u = x in u*u*u*u*u
  #-}

-- | Infix shorthand for 'plus'.
(+) :: Semiring a => a -> a -> a
+ :: forall a. Semiring a => a -> a -> a
(+) = a -> a -> a
forall a. Semiring a => a -> a -> a
plus
{-# INLINE (+) #-}

-- | Infix shorthand for 'times'.
(*) :: Semiring a => a -> a -> a
* :: forall a. Semiring a => a -> a -> a
(*) = a -> a -> a
forall a. Semiring a => a -> a -> a
times
{-# INLINE (*) #-}

-- | Infix shorthand for 'minus'.
(-) :: Ring a => a -> a -> a
(-) = a -> a -> a
forall a. Ring a => a -> a -> a
minus
{-# INLINE (-) #-}

-- | Map each element of the structure to a semiring, and combine the results
--   using 'plus'.
foldMapP :: (Foldable t, Semiring s) => (a -> s) -> t a -> s
foldMapP :: forall (t :: * -> *) s a.
(Foldable t, Semiring s) =>
(a -> s) -> t a -> s
foldMapP a -> s
f = (a -> s -> s) -> s -> t a -> s
forall a b. (a -> b -> b) -> b -> t a -> b
forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
Foldable.foldr (s -> s -> s
forall a. Semiring a => a -> a -> a
plus  (s -> s -> s) -> (a -> s) -> a -> s -> s
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> s
f) s
forall a. Semiring a => a
zero
{-# INLINE foldMapP #-}

-- | Map each element of the structure to a semiring, and combine the results
--   using 'times'.
foldMapT :: (Foldable t, Semiring s) => (a -> s) -> t a -> s
foldMapT :: forall (t :: * -> *) s a.
(Foldable t, Semiring s) =>
(a -> s) -> t a -> s
foldMapT a -> s
f = (a -> s -> s) -> s -> t a -> s
forall a b. (a -> b -> b) -> b -> t a -> b
forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
Foldable.foldr (s -> s -> s
forall a. Semiring a => a -> a -> a
times (s -> s -> s) -> (a -> s) -> a -> s -> s
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> s
f) s
forall a. Semiring a => a
one
{-# INLINE foldMapT #-}

infixr 9 #.
(#.) :: Coercible b c => (b -> c) -> (a -> b) -> a -> c
#. :: forall b c a. Coercible b c => (b -> c) -> (a -> b) -> a -> c
(#.) b -> c
_ = (a -> b) -> a -> c
forall a b. Coercible a b => a -> b
coerce

-- | The 'sum' function computes the additive sum of the elements in a structure.
--   This function is lazy. For a strict version, see 'sum''.
sum :: (Foldable t, Semiring a) => t a -> a
sum :: forall (t :: * -> *) a. (Foldable t, Semiring a) => t a -> a
sum = Add a -> a
forall a. Add a -> a
getAdd (Add a -> a) -> (t a -> Add a) -> t a -> a
forall b c a. Coercible b c => (b -> c) -> (a -> b) -> a -> c
#. (a -> Add a) -> t a -> Add a
forall m a. Monoid m => (a -> m) -> t a -> m
forall (t :: * -> *) m a.
(Foldable t, Monoid m) =>
(a -> m) -> t a -> m
foldMap a -> Add a
forall a. a -> Add a
Add
{-# INLINE sum #-}

-- | The 'product' function computes the product of the elements in a structure.
--   This function is lazy. for a strict version, see 'product''.
product :: (Foldable t, Semiring a) => t a -> a
product :: forall (t :: * -> *) a. (Foldable t, Semiring a) => t a -> a
product = Mul a -> a
forall a. Mul a -> a
getMul (Mul a -> a) -> (t a -> Mul a) -> t a -> a
forall b c a. Coercible b c => (b -> c) -> (a -> b) -> a -> c
#. (a -> Mul a) -> t a -> Mul a
forall m a. Monoid m => (a -> m) -> t a -> m
forall (t :: * -> *) m a.
(Foldable t, Monoid m) =>
(a -> m) -> t a -> m
foldMap a -> Mul a
forall a. a -> Mul a
Mul
{-# INLINE product #-}

-- | The 'sum'' function computes the additive sum of the elements in a structure.
--   This function is strict. For a lazy version, see 'sum'.
sum'  :: (Foldable t, Semiring a) => t a -> a
sum' :: forall (t :: * -> *) a. (Foldable t, Semiring a) => t a -> a
sum'  = (a -> a -> a) -> a -> t a -> a
forall b a. (b -> a -> b) -> b -> t a -> b
forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
Foldable.foldl' a -> a -> a
forall a. Semiring a => a -> a -> a
plus a
forall a. Semiring a => a
zero
{-# INLINE sum' #-}

-- | The 'product'' function computes the additive sum of the elements in a structure.
--   This function is strict. For a lazy version, see 'product'.
product' :: (Foldable t, Semiring a) => t a -> a
product' :: forall (t :: * -> *) a. (Foldable t, Semiring a) => t a -> a
product' = (a -> a -> a) -> a -> t a -> a
forall b a. (b -> a -> b) -> b -> t a -> b
forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
Foldable.foldl' a -> a -> a
forall a. Semiring a => a -> a -> a
times a
forall a. Semiring a => a
one
{-# INLINE product' #-}

-- | Monoid under 'plus'. Analogous to 'Data.Monoid.Sum', but
--   uses the 'Semiring' constraint rather than 'Num.Num'.
newtype Add a = Add { forall a. Add a -> a
getAdd :: a }
  deriving
    ( Add a
Add a -> Add a -> Bounded (Add a)
forall a. a -> a -> Bounded a
forall a. Bounded a => Add a
$cminBound :: forall a. Bounded a => Add a
minBound :: Add a
$cmaxBound :: forall a. Bounded a => Add a
maxBound :: Add a
Bounded
    , Int -> Add a
Add a -> Int
Add a -> [Add a]
Add a -> Add a
Add a -> Add a -> [Add a]
Add a -> Add a -> Add a -> [Add a]
(Add a -> Add a)
-> (Add a -> Add a)
-> (Int -> Add a)
-> (Add a -> Int)
-> (Add a -> [Add a])
-> (Add a -> Add a -> [Add a])
-> (Add a -> Add a -> [Add a])
-> (Add a -> Add a -> Add a -> [Add a])
-> Enum (Add a)
forall a. Enum a => Int -> Add a
forall a. Enum a => Add a -> Int
forall a. Enum a => Add a -> [Add a]
forall a. Enum a => Add a -> Add a
forall a. Enum a => Add a -> Add a -> [Add a]
forall a. Enum a => Add a -> Add a -> Add a -> [Add a]
forall a.
(a -> a)
-> (a -> a)
-> (Int -> a)
-> (a -> Int)
-> (a -> [a])
-> (a -> a -> [a])
-> (a -> a -> [a])
-> (a -> a -> a -> [a])
-> Enum a
$csucc :: forall a. Enum a => Add a -> Add a
succ :: Add a -> Add a
$cpred :: forall a. Enum a => Add a -> Add a
pred :: Add a -> Add a
$ctoEnum :: forall a. Enum a => Int -> Add a
toEnum :: Int -> Add a
$cfromEnum :: forall a. Enum a => Add a -> Int
fromEnum :: Add a -> Int
$cenumFrom :: forall a. Enum a => Add a -> [Add a]
enumFrom :: Add a -> [Add a]
$cenumFromThen :: forall a. Enum a => Add a -> Add a -> [Add a]
enumFromThen :: Add a -> Add a -> [Add a]
$cenumFromTo :: forall a. Enum a => Add a -> Add a -> [Add a]
enumFromTo :: Add a -> Add a -> [Add a]
$cenumFromThenTo :: forall a. Enum a => Add a -> Add a -> Add a -> [Add a]
enumFromThenTo :: Add a -> Add a -> Add a -> [Add a]
Enum
    , Add a -> Add a -> Bool
(Add a -> Add a -> Bool) -> (Add a -> Add a -> Bool) -> Eq (Add a)
forall a. Eq a => Add a -> Add a -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: forall a. Eq a => Add a -> Add a -> Bool
== :: Add a -> Add a -> Bool
$c/= :: forall a. Eq a => Add a -> Add a -> Bool
/= :: Add a -> Add a -> Bool
Eq
    , (forall m. Monoid m => Add m -> m)
-> (forall m a. Monoid m => (a -> m) -> Add a -> m)
-> (forall m a. Monoid m => (a -> m) -> Add a -> m)
-> (forall a b. (a -> b -> b) -> b -> Add a -> b)
-> (forall a b. (a -> b -> b) -> b -> Add a -> b)
-> (forall b a. (b -> a -> b) -> b -> Add a -> b)
-> (forall b a. (b -> a -> b) -> b -> Add a -> b)
-> (forall a. (a -> a -> a) -> Add a -> a)
-> (forall a. (a -> a -> a) -> Add a -> a)
-> (forall a. Add a -> [a])
-> (forall a. Add a -> Bool)
-> (forall a. Add a -> Int)
-> (forall a. Eq a => a -> Add a -> Bool)
-> (forall a. Ord a => Add a -> a)
-> (forall a. Ord a => Add a -> a)
-> (forall a. Num a => Add a -> a)
-> (forall a. Num a => Add a -> a)
-> Foldable Add
forall a. Eq a => a -> Add a -> Bool
forall a. Num a => Add a -> a
forall a. Ord a => Add a -> a
forall m. Monoid m => Add m -> m
forall a. Add a -> Bool
forall a. Add a -> Int
forall a. Add a -> [a]
forall a. (a -> a -> a) -> Add a -> a
forall m a. Monoid m => (a -> m) -> Add a -> m
forall b a. (b -> a -> b) -> b -> Add a -> b
forall a b. (a -> b -> b) -> b -> Add a -> b
forall (t :: * -> *).
(forall m. Monoid m => t m -> m)
-> (forall m a. Monoid m => (a -> m) -> t a -> m)
-> (forall m a. Monoid m => (a -> m) -> t a -> m)
-> (forall a b. (a -> b -> b) -> b -> t a -> b)
-> (forall a b. (a -> b -> b) -> b -> t a -> b)
-> (forall b a. (b -> a -> b) -> b -> t a -> b)
-> (forall b a. (b -> a -> b) -> b -> t a -> b)
-> (forall a. (a -> a -> a) -> t a -> a)
-> (forall a. (a -> a -> a) -> t a -> a)
-> (forall a. t a -> [a])
-> (forall a. t a -> Bool)
-> (forall a. t a -> Int)
-> (forall a. Eq a => a -> t a -> Bool)
-> (forall a. Ord a => t a -> a)
-> (forall a. Ord a => t a -> a)
-> (forall a. Num a => t a -> a)
-> (forall a. Num a => t a -> a)
-> Foldable t
$cfold :: forall m. Monoid m => Add m -> m
fold :: forall m. Monoid m => Add m -> m
$cfoldMap :: forall m a. Monoid m => (a -> m) -> Add a -> m
foldMap :: forall m a. Monoid m => (a -> m) -> Add a -> m
$cfoldMap' :: forall m a. Monoid m => (a -> m) -> Add a -> m
foldMap' :: forall m a. Monoid m => (a -> m) -> Add a -> m
$cfoldr :: forall a b. (a -> b -> b) -> b -> Add a -> b
foldr :: forall a b. (a -> b -> b) -> b -> Add a -> b
$cfoldr' :: forall a b. (a -> b -> b) -> b -> Add a -> b
foldr' :: forall a b. (a -> b -> b) -> b -> Add a -> b
$cfoldl :: forall b a. (b -> a -> b) -> b -> Add a -> b
foldl :: forall b a. (b -> a -> b) -> b -> Add a -> b
$cfoldl' :: forall b a. (b -> a -> b) -> b -> Add a -> b
foldl' :: forall b a. (b -> a -> b) -> b -> Add a -> b
$cfoldr1 :: forall a. (a -> a -> a) -> Add a -> a
foldr1 :: forall a. (a -> a -> a) -> Add a -> a
$cfoldl1 :: forall a. (a -> a -> a) -> Add a -> a
foldl1 :: forall a. (a -> a -> a) -> Add a -> a
$ctoList :: forall a. Add a -> [a]
toList :: forall a. Add a -> [a]
$cnull :: forall a. Add a -> Bool
null :: forall a. Add a -> Bool
$clength :: forall a. Add a -> Int
length :: forall a. Add a -> Int
$celem :: forall a. Eq a => a -> Add a -> Bool
elem :: forall a. Eq a => a -> Add a -> Bool
$cmaximum :: forall a. Ord a => Add a -> a
maximum :: forall a. Ord a => Add a -> a
$cminimum :: forall a. Ord a => Add a -> a
minimum :: forall a. Ord a => Add a -> a
$csum :: forall a. Num a => Add a -> a
sum :: forall a. Num a => Add a -> a
$cproduct :: forall a. Num a => Add a -> a
product :: forall a. Num a => Add a -> a
Foldable
    , Num (Add a)
Num (Add a) =>
(Add a -> Add a -> Add a)
-> (Add a -> Add a) -> (Rational -> Add a) -> Fractional (Add a)
Rational -> Add a
Add a -> Add a
Add a -> Add a -> Add a
forall a. Fractional a => Num (Add a)
forall a. Fractional a => Rational -> Add a
forall a. Fractional a => Add a -> Add a
forall a. Fractional a => Add a -> Add a -> Add a
forall a.
Num a =>
(a -> a -> a) -> (a -> a) -> (Rational -> a) -> Fractional a
$c/ :: forall a. Fractional a => Add a -> Add a -> Add a
/ :: Add a -> Add a -> Add a
$crecip :: forall a. Fractional a => Add a -> Add a
recip :: Add a -> Add a
$cfromRational :: forall a. Fractional a => Rational -> Add a
fromRational :: Rational -> Add a
Fractional
    , (forall a b. (a -> b) -> Add a -> Add b)
-> (forall a b. a -> Add b -> Add a) -> Functor Add
forall a b. a -> Add b -> Add a
forall a b. (a -> b) -> Add a -> Add b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
$cfmap :: forall a b. (a -> b) -> Add a -> Add b
fmap :: forall a b. (a -> b) -> Add a -> Add b
$c<$ :: forall a b. a -> Add b -> Add a
<$ :: forall a b. a -> Add b -> Add a
Functor
    , (forall x. Add a -> Rep (Add a) x)
-> (forall x. Rep (Add a) x -> Add a) -> Generic (Add a)
forall x. Rep (Add a) x -> Add a
forall x. Add a -> Rep (Add a) x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall a x. Rep (Add a) x -> Add a
forall a x. Add a -> Rep (Add a) x
$cfrom :: forall a x. Add a -> Rep (Add a) x
from :: forall x. Add a -> Rep (Add a) x
$cto :: forall a x. Rep (Add a) x -> Add a
to :: forall x. Rep (Add a) x -> Add a
Generic
    , (forall a. Add a -> Rep1 Add a)
-> (forall a. Rep1 Add a -> Add a) -> Generic1 Add
forall a. Rep1 Add a -> Add a
forall a. Add a -> Rep1 Add a
forall k (f :: k -> *).
(forall (a :: k). f a -> Rep1 f a)
-> (forall (a :: k). Rep1 f a -> f a) -> Generic1 f
$cfrom1 :: forall a. Add a -> Rep1 Add a
from1 :: forall a. Add a -> Rep1 Add a
$cto1 :: forall a. Rep1 Add a -> Add a
to1 :: forall a. Rep1 Add a -> Add a
Generic1
    , Integer -> Add a
Add a -> Add a
Add a -> Add a -> Add a
(Add a -> Add a -> Add a)
-> (Add a -> Add a -> Add a)
-> (Add a -> Add a -> Add a)
-> (Add a -> Add a)
-> (Add a -> Add a)
-> (Add a -> Add a)
-> (Integer -> Add a)
-> Num (Add a)
forall a. Num a => Integer -> Add a
forall a. Num a => Add a -> Add a
forall a. Num a => Add a -> Add a -> Add a
forall a.
(a -> a -> a)
-> (a -> a -> a)
-> (a -> a -> a)
-> (a -> a)
-> (a -> a)
-> (a -> a)
-> (Integer -> a)
-> Num a
$c+ :: forall a. Num a => Add a -> Add a -> Add a
+ :: Add a -> Add a -> Add a
$c- :: forall a. Num a => Add a -> Add a -> Add a
- :: Add a -> Add a -> Add a
$c* :: forall a. Num a => Add a -> Add a -> Add a
* :: Add a -> Add a -> Add a
$cnegate :: forall a. Num a => Add a -> Add a
negate :: Add a -> Add a
$cabs :: forall a. Num a => Add a -> Add a
abs :: Add a -> Add a
$csignum :: forall a. Num a => Add a -> Add a
signum :: Add a -> Add a
$cfromInteger :: forall a. Num a => Integer -> Add a
fromInteger :: Integer -> Add a
Num.Num
    , Eq (Add a)
Eq (Add a) =>
(Add a -> Add a -> Ordering)
-> (Add a -> Add a -> Bool)
-> (Add a -> Add a -> Bool)
-> (Add a -> Add a -> Bool)
-> (Add a -> Add a -> Bool)
-> (Add a -> Add a -> Add a)
-> (Add a -> Add a -> Add a)
-> Ord (Add a)
Add a -> Add a -> Bool
Add a -> Add a -> Ordering
Add a -> Add a -> Add a
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
forall a. Ord a => Eq (Add a)
forall a. Ord a => Add a -> Add a -> Bool
forall a. Ord a => Add a -> Add a -> Ordering
forall a. Ord a => Add a -> Add a -> Add a
$ccompare :: forall a. Ord a => Add a -> Add a -> Ordering
compare :: Add a -> Add a -> Ordering
$c< :: forall a. Ord a => Add a -> Add a -> Bool
< :: Add a -> Add a -> Bool
$c<= :: forall a. Ord a => Add a -> Add a -> Bool
<= :: Add a -> Add a -> Bool
$c> :: forall a. Ord a => Add a -> Add a -> Bool
> :: Add a -> Add a -> Bool
$c>= :: forall a. Ord a => Add a -> Add a -> Bool
>= :: Add a -> Add a -> Bool
$cmax :: forall a. Ord a => Add a -> Add a -> Add a
max :: Add a -> Add a -> Add a
$cmin :: forall a. Ord a => Add a -> Add a -> Add a
min :: Add a -> Add a -> Add a
Ord
    , ReadPrec [Add a]
ReadPrec (Add a)
Int -> ReadS (Add a)
ReadS [Add a]
(Int -> ReadS (Add a))
-> ReadS [Add a]
-> ReadPrec (Add a)
-> ReadPrec [Add a]
-> Read (Add a)
forall a. Read a => ReadPrec [Add a]
forall a. Read a => ReadPrec (Add a)
forall a. Read a => Int -> ReadS (Add a)
forall a. Read a => ReadS [Add a]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
$creadsPrec :: forall a. Read a => Int -> ReadS (Add a)
readsPrec :: Int -> ReadS (Add a)
$creadList :: forall a. Read a => ReadS [Add a]
readList :: ReadS [Add a]
$creadPrec :: forall a. Read a => ReadPrec (Add a)
readPrec :: ReadPrec (Add a)
$creadListPrec :: forall a. Read a => ReadPrec [Add a]
readListPrec :: ReadPrec [Add a]
Read
    , Num (Add a)
Ord (Add a)
(Num (Add a), Ord (Add a)) => (Add a -> Rational) -> Real (Add a)
Add a -> Rational
forall a. (Num a, Ord a) => (a -> Rational) -> Real a
forall a. Real a => Num (Add a)
forall a. Real a => Ord (Add a)
forall a. Real a => Add a -> Rational
$ctoRational :: forall a. Real a => Add a -> Rational
toRational :: Add a -> Rational
Real
    , Fractional (Add a)
Real (Add a)
(Real (Add a), Fractional (Add a)) =>
(forall b. Integral b => Add a -> (b, Add a))
-> (forall b. Integral b => Add a -> b)
-> (forall b. Integral b => Add a -> b)
-> (forall b. Integral b => Add a -> b)
-> (forall b. Integral b => Add a -> b)
-> RealFrac (Add a)
forall b. Integral b => Add a -> b
forall b. Integral b => Add a -> (b, Add a)
forall a.
(Real a, Fractional a) =>
(forall b. Integral b => a -> (b, a))
-> (forall b. Integral b => a -> b)
-> (forall b. Integral b => a -> b)
-> (forall b. Integral b => a -> b)
-> (forall b. Integral b => a -> b)
-> RealFrac a
forall a. RealFrac a => Fractional (Add a)
forall a. RealFrac a => Real (Add a)
forall a b. (RealFrac a, Integral b) => Add a -> b
forall a b. (RealFrac a, Integral b) => Add a -> (b, Add a)
$cproperFraction :: forall a b. (RealFrac a, Integral b) => Add a -> (b, Add a)
properFraction :: forall b. Integral b => Add a -> (b, Add a)
$ctruncate :: forall a b. (RealFrac a, Integral b) => Add a -> b
truncate :: forall b. Integral b => Add a -> b
$cround :: forall a b. (RealFrac a, Integral b) => Add a -> b
round :: forall b. Integral b => Add a -> b
$cceiling :: forall a b. (RealFrac a, Integral b) => Add a -> b
ceiling :: forall b. Integral b => Add a -> b
$cfloor :: forall a b. (RealFrac a, Integral b) => Add a -> b
floor :: forall b. Integral b => Add a -> b
RealFrac
    , Int -> Add a -> ShowS
[Add a] -> ShowS
Add a -> [Char]
(Int -> Add a -> ShowS)
-> (Add a -> [Char]) -> ([Add a] -> ShowS) -> Show (Add a)
forall a. Show a => Int -> Add a -> ShowS
forall a. Show a => [Add a] -> ShowS
forall a. Show a => Add a -> [Char]
forall a.
(Int -> a -> ShowS) -> (a -> [Char]) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: forall a. Show a => Int -> Add a -> ShowS
showsPrec :: Int -> Add a -> ShowS
$cshow :: forall a. Show a => Add a -> [Char]
show :: Add a -> [Char]
$cshowList :: forall a. Show a => [Add a] -> ShowS
showList :: [Add a] -> ShowS
Show
    , Ptr (Add a) -> IO (Add a)
Ptr (Add a) -> Int -> IO (Add a)
Ptr (Add a) -> Int -> Add a -> IO ()
Ptr (Add a) -> Add a -> IO ()
Add a -> Int
(Add a -> Int)
-> (Add a -> Int)
-> (Ptr (Add a) -> Int -> IO (Add a))
-> (Ptr (Add a) -> Int -> Add a -> IO ())
-> (forall b. Ptr b -> Int -> IO (Add a))
-> (forall b. Ptr b -> Int -> Add a -> IO ())
-> (Ptr (Add a) -> IO (Add a))
-> (Ptr (Add a) -> Add a -> IO ())
-> Storable (Add a)
forall b. Ptr b -> Int -> IO (Add a)
forall b. Ptr b -> Int -> Add a -> IO ()
forall a. Storable a => Ptr (Add a) -> IO (Add a)
forall a. Storable a => Ptr (Add a) -> Int -> IO (Add a)
forall a. Storable a => Ptr (Add a) -> Int -> Add a -> IO ()
forall a. Storable a => Ptr (Add a) -> Add a -> IO ()
forall a. Storable a => Add a -> Int
forall a b. Storable a => Ptr b -> Int -> IO (Add a)
forall a b. Storable a => Ptr b -> Int -> Add a -> IO ()
forall a.
(a -> Int)
-> (a -> Int)
-> (Ptr a -> Int -> IO a)
-> (Ptr a -> Int -> a -> IO ())
-> (forall b. Ptr b -> Int -> IO a)
-> (forall b. Ptr b -> Int -> a -> IO ())
-> (Ptr a -> IO a)
-> (Ptr a -> a -> IO ())
-> Storable a
$csizeOf :: forall a. Storable a => Add a -> Int
sizeOf :: Add a -> Int
$calignment :: forall a. Storable a => Add a -> Int
alignment :: Add a -> Int
$cpeekElemOff :: forall a. Storable a => Ptr (Add a) -> Int -> IO (Add a)
peekElemOff :: Ptr (Add a) -> Int -> IO (Add a)
$cpokeElemOff :: forall a. Storable a => Ptr (Add a) -> Int -> Add a -> IO ()
pokeElemOff :: Ptr (Add a) -> Int -> Add a -> IO ()
$cpeekByteOff :: forall a b. Storable a => Ptr b -> Int -> IO (Add a)
peekByteOff :: forall b. Ptr b -> Int -> IO (Add a)
$cpokeByteOff :: forall a b. Storable a => Ptr b -> Int -> Add a -> IO ()
pokeByteOff :: forall b. Ptr b -> Int -> Add a -> IO ()
$cpeek :: forall a. Storable a => Ptr (Add a) -> IO (Add a)
peek :: Ptr (Add a) -> IO (Add a)
$cpoke :: forall a. Storable a => Ptr (Add a) -> Add a -> IO ()
poke :: Ptr (Add a) -> Add a -> IO ()
Storable
    , Functor Add
Foldable Add
(Functor Add, Foldable Add) =>
(forall (f :: * -> *) a b.
 Applicative f =>
 (a -> f b) -> Add a -> f (Add b))
-> (forall (f :: * -> *) a.
    Applicative f =>
    Add (f a) -> f (Add a))
-> (forall (m :: * -> *) a b.
    Monad m =>
    (a -> m b) -> Add a -> m (Add b))
-> (forall (m :: * -> *) a. Monad m => Add (m a) -> m (Add a))
-> Traversable Add
forall (t :: * -> *).
(Functor t, Foldable t) =>
(forall (f :: * -> *) a b.
 Applicative f =>
 (a -> f b) -> t a -> f (t b))
-> (forall (f :: * -> *) a. Applicative f => t (f a) -> f (t a))
-> (forall (m :: * -> *) a b.
    Monad m =>
    (a -> m b) -> t a -> m (t b))
-> (forall (m :: * -> *) a. Monad m => t (m a) -> m (t a))
-> Traversable t
forall (m :: * -> *) a. Monad m => Add (m a) -> m (Add a)
forall (f :: * -> *) a. Applicative f => Add (f a) -> f (Add a)
forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> Add a -> m (Add b)
forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> Add a -> f (Add b)
$ctraverse :: forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> Add a -> f (Add b)
traverse :: forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> Add a -> f (Add b)
$csequenceA :: forall (f :: * -> *) a. Applicative f => Add (f a) -> f (Add a)
sequenceA :: forall (f :: * -> *) a. Applicative f => Add (f a) -> f (Add a)
$cmapM :: forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> Add a -> m (Add b)
mapM :: forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> Add a -> m (Add b)
$csequence :: forall (m :: * -> *) a. Monad m => Add (m a) -> m (Add a)
sequence :: forall (m :: * -> *) a. Monad m => Add (m a) -> m (Add a)
Traversable
    , Typeable
    )

instance Semiring a => Semigroup (Add a) where
  Add a
a <> :: Add a -> Add a -> Add a
<> Add a
b = a -> Add a
forall a. a -> Add a
Add (a
a a -> a -> a
forall a. Semiring a => a -> a -> a
+ a
b)
  stimes :: forall b. Integral b => b -> Add a -> Add a
stimes b
n (Add a
a) = a -> Add a
forall a. a -> Add a
Add (Natural -> a
forall a. Semiring a => Natural -> a
fromNatural (b -> Natural
forall a b. (Integral a, Num b) => a -> b
Real.fromIntegral b
n) a -> a -> a
forall a. Semiring a => a -> a -> a
* a
a)
  {-# INLINE (<>) #-}

instance Semiring a => Monoid (Add a) where
  mempty :: Add a
mempty = a -> Add a
forall a. a -> Add a
Add a
forall a. Semiring a => a
zero
  mappend :: Add a -> Add a -> Add a
mappend = Add a -> Add a -> Add a
forall a. Semigroup a => a -> a -> a
(<>)
  {-# INLINE mempty #-}
  {-# INLINE mappend #-}

-- | This is an internal type, solely for purposes
-- of default implementation of 'fromNatural'.
newtype Add' a = Add' { forall a. Add' a -> a
getAdd' :: a }

instance Semiring a => Semigroup (Add' a) where
  Add' a
a <> :: Add' a -> Add' a -> Add' a
<> Add' a
b = a -> Add' a
forall a. a -> Add' a
Add' (a
a a -> a -> a
forall a. Semiring a => a -> a -> a
+ a
b)

-- | Monoid under 'times'. Analogous to 'Data.Monoid.Product', but
--   uses the 'Semiring' constraint rather than 'Num.Num'.
newtype Mul a = Mul { forall a. Mul a -> a
getMul :: a }
  deriving
    ( Mul a
Mul a -> Mul a -> Bounded (Mul a)
forall a. a -> a -> Bounded a
forall a. Bounded a => Mul a
$cminBound :: forall a. Bounded a => Mul a
minBound :: Mul a
$cmaxBound :: forall a. Bounded a => Mul a
maxBound :: Mul a
Bounded
    , Int -> Mul a
Mul a -> Int
Mul a -> [Mul a]
Mul a -> Mul a
Mul a -> Mul a -> [Mul a]
Mul a -> Mul a -> Mul a -> [Mul a]
(Mul a -> Mul a)
-> (Mul a -> Mul a)
-> (Int -> Mul a)
-> (Mul a -> Int)
-> (Mul a -> [Mul a])
-> (Mul a -> Mul a -> [Mul a])
-> (Mul a -> Mul a -> [Mul a])
-> (Mul a -> Mul a -> Mul a -> [Mul a])
-> Enum (Mul a)
forall a. Enum a => Int -> Mul a
forall a. Enum a => Mul a -> Int
forall a. Enum a => Mul a -> [Mul a]
forall a. Enum a => Mul a -> Mul a
forall a. Enum a => Mul a -> Mul a -> [Mul a]
forall a. Enum a => Mul a -> Mul a -> Mul a -> [Mul a]
forall a.
(a -> a)
-> (a -> a)
-> (Int -> a)
-> (a -> Int)
-> (a -> [a])
-> (a -> a -> [a])
-> (a -> a -> [a])
-> (a -> a -> a -> [a])
-> Enum a
$csucc :: forall a. Enum a => Mul a -> Mul a
succ :: Mul a -> Mul a
$cpred :: forall a. Enum a => Mul a -> Mul a
pred :: Mul a -> Mul a
$ctoEnum :: forall a. Enum a => Int -> Mul a
toEnum :: Int -> Mul a
$cfromEnum :: forall a. Enum a => Mul a -> Int
fromEnum :: Mul a -> Int
$cenumFrom :: forall a. Enum a => Mul a -> [Mul a]
enumFrom :: Mul a -> [Mul a]
$cenumFromThen :: forall a. Enum a => Mul a -> Mul a -> [Mul a]
enumFromThen :: Mul a -> Mul a -> [Mul a]
$cenumFromTo :: forall a. Enum a => Mul a -> Mul a -> [Mul a]
enumFromTo :: Mul a -> Mul a -> [Mul a]
$cenumFromThenTo :: forall a. Enum a => Mul a -> Mul a -> Mul a -> [Mul a]
enumFromThenTo :: Mul a -> Mul a -> Mul a -> [Mul a]
Enum
    , Mul a -> Mul a -> Bool
(Mul a -> Mul a -> Bool) -> (Mul a -> Mul a -> Bool) -> Eq (Mul a)
forall a. Eq a => Mul a -> Mul a -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: forall a. Eq a => Mul a -> Mul a -> Bool
== :: Mul a -> Mul a -> Bool
$c/= :: forall a. Eq a => Mul a -> Mul a -> Bool
/= :: Mul a -> Mul a -> Bool
Eq
    , (forall m. Monoid m => Mul m -> m)
-> (forall m a. Monoid m => (a -> m) -> Mul a -> m)
-> (forall m a. Monoid m => (a -> m) -> Mul a -> m)
-> (forall a b. (a -> b -> b) -> b -> Mul a -> b)
-> (forall a b. (a -> b -> b) -> b -> Mul a -> b)
-> (forall b a. (b -> a -> b) -> b -> Mul a -> b)
-> (forall b a. (b -> a -> b) -> b -> Mul a -> b)
-> (forall a. (a -> a -> a) -> Mul a -> a)
-> (forall a. (a -> a -> a) -> Mul a -> a)
-> (forall a. Mul a -> [a])
-> (forall a. Mul a -> Bool)
-> (forall a. Mul a -> Int)
-> (forall a. Eq a => a -> Mul a -> Bool)
-> (forall a. Ord a => Mul a -> a)
-> (forall a. Ord a => Mul a -> a)
-> (forall a. Num a => Mul a -> a)
-> (forall a. Num a => Mul a -> a)
-> Foldable Mul
forall a. Eq a => a -> Mul a -> Bool
forall a. Num a => Mul a -> a
forall a. Ord a => Mul a -> a
forall m. Monoid m => Mul m -> m
forall a. Mul a -> Bool
forall a. Mul a -> Int
forall a. Mul a -> [a]
forall a. (a -> a -> a) -> Mul a -> a
forall m a. Monoid m => (a -> m) -> Mul a -> m
forall b a. (b -> a -> b) -> b -> Mul a -> b
forall a b. (a -> b -> b) -> b -> Mul a -> b
forall (t :: * -> *).
(forall m. Monoid m => t m -> m)
-> (forall m a. Monoid m => (a -> m) -> t a -> m)
-> (forall m a. Monoid m => (a -> m) -> t a -> m)
-> (forall a b. (a -> b -> b) -> b -> t a -> b)
-> (forall a b. (a -> b -> b) -> b -> t a -> b)
-> (forall b a. (b -> a -> b) -> b -> t a -> b)
-> (forall b a. (b -> a -> b) -> b -> t a -> b)
-> (forall a. (a -> a -> a) -> t a -> a)
-> (forall a. (a -> a -> a) -> t a -> a)
-> (forall a. t a -> [a])
-> (forall a. t a -> Bool)
-> (forall a. t a -> Int)
-> (forall a. Eq a => a -> t a -> Bool)
-> (forall a. Ord a => t a -> a)
-> (forall a. Ord a => t a -> a)
-> (forall a. Num a => t a -> a)
-> (forall a. Num a => t a -> a)
-> Foldable t
$cfold :: forall m. Monoid m => Mul m -> m
fold :: forall m. Monoid m => Mul m -> m
$cfoldMap :: forall m a. Monoid m => (a -> m) -> Mul a -> m
foldMap :: forall m a. Monoid m => (a -> m) -> Mul a -> m
$cfoldMap' :: forall m a. Monoid m => (a -> m) -> Mul a -> m
foldMap' :: forall m a. Monoid m => (a -> m) -> Mul a -> m
$cfoldr :: forall a b. (a -> b -> b) -> b -> Mul a -> b
foldr :: forall a b. (a -> b -> b) -> b -> Mul a -> b
$cfoldr' :: forall a b. (a -> b -> b) -> b -> Mul a -> b
foldr' :: forall a b. (a -> b -> b) -> b -> Mul a -> b
$cfoldl :: forall b a. (b -> a -> b) -> b -> Mul a -> b
foldl :: forall b a. (b -> a -> b) -> b -> Mul a -> b
$cfoldl' :: forall b a. (b -> a -> b) -> b -> Mul a -> b
foldl' :: forall b a. (b -> a -> b) -> b -> Mul a -> b
$cfoldr1 :: forall a. (a -> a -> a) -> Mul a -> a
foldr1 :: forall a. (a -> a -> a) -> Mul a -> a
$cfoldl1 :: forall a. (a -> a -> a) -> Mul a -> a
foldl1 :: forall a. (a -> a -> a) -> Mul a -> a
$ctoList :: forall a. Mul a -> [a]
toList :: forall a. Mul a -> [a]
$cnull :: forall a. Mul a -> Bool
null :: forall a. Mul a -> Bool
$clength :: forall a. Mul a -> Int
length :: forall a. Mul a -> Int
$celem :: forall a. Eq a => a -> Mul a -> Bool
elem :: forall a. Eq a => a -> Mul a -> Bool
$cmaximum :: forall a. Ord a => Mul a -> a
maximum :: forall a. Ord a => Mul a -> a
$cminimum :: forall a. Ord a => Mul a -> a
minimum :: forall a. Ord a => Mul a -> a
$csum :: forall a. Num a => Mul a -> a
sum :: forall a. Num a => Mul a -> a
$cproduct :: forall a. Num a => Mul a -> a
product :: forall a. Num a => Mul a -> a
Foldable
    , Num (Mul a)
Num (Mul a) =>
(Mul a -> Mul a -> Mul a)
-> (Mul a -> Mul a) -> (Rational -> Mul a) -> Fractional (Mul a)
Rational -> Mul a
Mul a -> Mul a
Mul a -> Mul a -> Mul a
forall a. Fractional a => Num (Mul a)
forall a. Fractional a => Rational -> Mul a
forall a. Fractional a => Mul a -> Mul a
forall a. Fractional a => Mul a -> Mul a -> Mul a
forall a.
Num a =>
(a -> a -> a) -> (a -> a) -> (Rational -> a) -> Fractional a
$c/ :: forall a. Fractional a => Mul a -> Mul a -> Mul a
/ :: Mul a -> Mul a -> Mul a
$crecip :: forall a. Fractional a => Mul a -> Mul a
recip :: Mul a -> Mul a
$cfromRational :: forall a. Fractional a => Rational -> Mul a
fromRational :: Rational -> Mul a
Fractional
    , (forall a b. (a -> b) -> Mul a -> Mul b)
-> (forall a b. a -> Mul b -> Mul a) -> Functor Mul
forall a b. a -> Mul b -> Mul a
forall a b. (a -> b) -> Mul a -> Mul b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
$cfmap :: forall a b. (a -> b) -> Mul a -> Mul b
fmap :: forall a b. (a -> b) -> Mul a -> Mul b
$c<$ :: forall a b. a -> Mul b -> Mul a
<$ :: forall a b. a -> Mul b -> Mul a
Functor
    , (forall x. Mul a -> Rep (Mul a) x)
-> (forall x. Rep (Mul a) x -> Mul a) -> Generic (Mul a)
forall x. Rep (Mul a) x -> Mul a
forall x. Mul a -> Rep (Mul a) x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall a x. Rep (Mul a) x -> Mul a
forall a x. Mul a -> Rep (Mul a) x
$cfrom :: forall a x. Mul a -> Rep (Mul a) x
from :: forall x. Mul a -> Rep (Mul a) x
$cto :: forall a x. Rep (Mul a) x -> Mul a
to :: forall x. Rep (Mul a) x -> Mul a
Generic
    , (forall a. Mul a -> Rep1 Mul a)
-> (forall a. Rep1 Mul a -> Mul a) -> Generic1 Mul
forall a. Rep1 Mul a -> Mul a
forall a. Mul a -> Rep1 Mul a
forall k (f :: k -> *).
(forall (a :: k). f a -> Rep1 f a)
-> (forall (a :: k). Rep1 f a -> f a) -> Generic1 f
$cfrom1 :: forall a. Mul a -> Rep1 Mul a
from1 :: forall a. Mul a -> Rep1 Mul a
$cto1 :: forall a. Rep1 Mul a -> Mul a
to1 :: forall a. Rep1 Mul a -> Mul a
Generic1
    , Integer -> Mul a
Mul a -> Mul a
Mul a -> Mul a -> Mul a
(Mul a -> Mul a -> Mul a)
-> (Mul a -> Mul a -> Mul a)
-> (Mul a -> Mul a -> Mul a)
-> (Mul a -> Mul a)
-> (Mul a -> Mul a)
-> (Mul a -> Mul a)
-> (Integer -> Mul a)
-> Num (Mul a)
forall a. Num a => Integer -> Mul a
forall a. Num a => Mul a -> Mul a
forall a. Num a => Mul a -> Mul a -> Mul a
forall a.
(a -> a -> a)
-> (a -> a -> a)
-> (a -> a -> a)
-> (a -> a)
-> (a -> a)
-> (a -> a)
-> (Integer -> a)
-> Num a
$c+ :: forall a. Num a => Mul a -> Mul a -> Mul a
+ :: Mul a -> Mul a -> Mul a
$c- :: forall a. Num a => Mul a -> Mul a -> Mul a
- :: Mul a -> Mul a -> Mul a
$c* :: forall a. Num a => Mul a -> Mul a -> Mul a
* :: Mul a -> Mul a -> Mul a
$cnegate :: forall a. Num a => Mul a -> Mul a
negate :: Mul a -> Mul a
$cabs :: forall a. Num a => Mul a -> Mul a
abs :: Mul a -> Mul a
$csignum :: forall a. Num a => Mul a -> Mul a
signum :: Mul a -> Mul a
$cfromInteger :: forall a. Num a => Integer -> Mul a
fromInteger :: Integer -> Mul a
Num.Num
    , Eq (Mul a)
Eq (Mul a) =>
(Mul a -> Mul a -> Ordering)
-> (Mul a -> Mul a -> Bool)
-> (Mul a -> Mul a -> Bool)
-> (Mul a -> Mul a -> Bool)
-> (Mul a -> Mul a -> Bool)
-> (Mul a -> Mul a -> Mul a)
-> (Mul a -> Mul a -> Mul a)
-> Ord (Mul a)
Mul a -> Mul a -> Bool
Mul a -> Mul a -> Ordering
Mul a -> Mul a -> Mul a
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
forall a. Ord a => Eq (Mul a)
forall a. Ord a => Mul a -> Mul a -> Bool
forall a. Ord a => Mul a -> Mul a -> Ordering
forall a. Ord a => Mul a -> Mul a -> Mul a
$ccompare :: forall a. Ord a => Mul a -> Mul a -> Ordering
compare :: Mul a -> Mul a -> Ordering
$c< :: forall a. Ord a => Mul a -> Mul a -> Bool
< :: Mul a -> Mul a -> Bool
$c<= :: forall a. Ord a => Mul a -> Mul a -> Bool
<= :: Mul a -> Mul a -> Bool
$c> :: forall a. Ord a => Mul a -> Mul a -> Bool
> :: Mul a -> Mul a -> Bool
$c>= :: forall a. Ord a => Mul a -> Mul a -> Bool
>= :: Mul a -> Mul a -> Bool
$cmax :: forall a. Ord a => Mul a -> Mul a -> Mul a
max :: Mul a -> Mul a -> Mul a
$cmin :: forall a. Ord a => Mul a -> Mul a -> Mul a
min :: Mul a -> Mul a -> Mul a
Ord
    , ReadPrec [Mul a]
ReadPrec (Mul a)
Int -> ReadS (Mul a)
ReadS [Mul a]
(Int -> ReadS (Mul a))
-> ReadS [Mul a]
-> ReadPrec (Mul a)
-> ReadPrec [Mul a]
-> Read (Mul a)
forall a. Read a => ReadPrec [Mul a]
forall a. Read a => ReadPrec (Mul a)
forall a. Read a => Int -> ReadS (Mul a)
forall a. Read a => ReadS [Mul a]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
$creadsPrec :: forall a. Read a => Int -> ReadS (Mul a)
readsPrec :: Int -> ReadS (Mul a)
$creadList :: forall a. Read a => ReadS [Mul a]
readList :: ReadS [Mul a]
$creadPrec :: forall a. Read a => ReadPrec (Mul a)
readPrec :: ReadPrec (Mul a)
$creadListPrec :: forall a. Read a => ReadPrec [Mul a]
readListPrec :: ReadPrec [Mul a]
Read
    , Num (Mul a)
Ord (Mul a)
(Num (Mul a), Ord (Mul a)) => (Mul a -> Rational) -> Real (Mul a)
Mul a -> Rational
forall a. (Num a, Ord a) => (a -> Rational) -> Real a
forall a. Real a => Num (Mul a)
forall a. Real a => Ord (Mul a)
forall a. Real a => Mul a -> Rational
$ctoRational :: forall a. Real a => Mul a -> Rational
toRational :: Mul a -> Rational
Real
    , Fractional (Mul a)
Real (Mul a)
(Real (Mul a), Fractional (Mul a)) =>
(forall b. Integral b => Mul a -> (b, Mul a))
-> (forall b. Integral b => Mul a -> b)
-> (forall b. Integral b => Mul a -> b)
-> (forall b. Integral b => Mul a -> b)
-> (forall b. Integral b => Mul a -> b)
-> RealFrac (Mul a)
forall b. Integral b => Mul a -> b
forall b. Integral b => Mul a -> (b, Mul a)
forall a.
(Real a, Fractional a) =>
(forall b. Integral b => a -> (b, a))
-> (forall b. Integral b => a -> b)
-> (forall b. Integral b => a -> b)
-> (forall b. Integral b => a -> b)
-> (forall b. Integral b => a -> b)
-> RealFrac a
forall a. RealFrac a => Fractional (Mul a)
forall a. RealFrac a => Real (Mul a)
forall a b. (RealFrac a, Integral b) => Mul a -> b
forall a b. (RealFrac a, Integral b) => Mul a -> (b, Mul a)
$cproperFraction :: forall a b. (RealFrac a, Integral b) => Mul a -> (b, Mul a)
properFraction :: forall b. Integral b => Mul a -> (b, Mul a)
$ctruncate :: forall a b. (RealFrac a, Integral b) => Mul a -> b
truncate :: forall b. Integral b => Mul a -> b
$cround :: forall a b. (RealFrac a, Integral b) => Mul a -> b
round :: forall b. Integral b => Mul a -> b
$cceiling :: forall a b. (RealFrac a, Integral b) => Mul a -> b
ceiling :: forall b. Integral b => Mul a -> b
$cfloor :: forall a b. (RealFrac a, Integral b) => Mul a -> b
floor :: forall b. Integral b => Mul a -> b
RealFrac
    , Int -> Mul a -> ShowS
[Mul a] -> ShowS
Mul a -> [Char]
(Int -> Mul a -> ShowS)
-> (Mul a -> [Char]) -> ([Mul a] -> ShowS) -> Show (Mul a)
forall a. Show a => Int -> Mul a -> ShowS
forall a. Show a => [Mul a] -> ShowS
forall a. Show a => Mul a -> [Char]
forall a.
(Int -> a -> ShowS) -> (a -> [Char]) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: forall a. Show a => Int -> Mul a -> ShowS
showsPrec :: Int -> Mul a -> ShowS
$cshow :: forall a. Show a => Mul a -> [Char]
show :: Mul a -> [Char]
$cshowList :: forall a. Show a => [Mul a] -> ShowS
showList :: [Mul a] -> ShowS
Show
    , Ptr (Mul a) -> IO (Mul a)
Ptr (Mul a) -> Int -> IO (Mul a)
Ptr (Mul a) -> Int -> Mul a -> IO ()
Ptr (Mul a) -> Mul a -> IO ()
Mul a -> Int
(Mul a -> Int)
-> (Mul a -> Int)
-> (Ptr (Mul a) -> Int -> IO (Mul a))
-> (Ptr (Mul a) -> Int -> Mul a -> IO ())
-> (forall b. Ptr b -> Int -> IO (Mul a))
-> (forall b. Ptr b -> Int -> Mul a -> IO ())
-> (Ptr (Mul a) -> IO (Mul a))
-> (Ptr (Mul a) -> Mul a -> IO ())
-> Storable (Mul a)
forall b. Ptr b -> Int -> IO (Mul a)
forall b. Ptr b -> Int -> Mul a -> IO ()
forall a. Storable a => Ptr (Mul a) -> IO (Mul a)
forall a. Storable a => Ptr (Mul a) -> Int -> IO (Mul a)
forall a. Storable a => Ptr (Mul a) -> Int -> Mul a -> IO ()
forall a. Storable a => Ptr (Mul a) -> Mul a -> IO ()
forall a. Storable a => Mul a -> Int
forall a b. Storable a => Ptr b -> Int -> IO (Mul a)
forall a b. Storable a => Ptr b -> Int -> Mul a -> IO ()
forall a.
(a -> Int)
-> (a -> Int)
-> (Ptr a -> Int -> IO a)
-> (Ptr a -> Int -> a -> IO ())
-> (forall b. Ptr b -> Int -> IO a)
-> (forall b. Ptr b -> Int -> a -> IO ())
-> (Ptr a -> IO a)
-> (Ptr a -> a -> IO ())
-> Storable a
$csizeOf :: forall a. Storable a => Mul a -> Int
sizeOf :: Mul a -> Int
$calignment :: forall a. Storable a => Mul a -> Int
alignment :: Mul a -> Int
$cpeekElemOff :: forall a. Storable a => Ptr (Mul a) -> Int -> IO (Mul a)
peekElemOff :: Ptr (Mul a) -> Int -> IO (Mul a)
$cpokeElemOff :: forall a. Storable a => Ptr (Mul a) -> Int -> Mul a -> IO ()
pokeElemOff :: Ptr (Mul a) -> Int -> Mul a -> IO ()
$cpeekByteOff :: forall a b. Storable a => Ptr b -> Int -> IO (Mul a)
peekByteOff :: forall b. Ptr b -> Int -> IO (Mul a)
$cpokeByteOff :: forall a b. Storable a => Ptr b -> Int -> Mul a -> IO ()
pokeByteOff :: forall b. Ptr b -> Int -> Mul a -> IO ()
$cpeek :: forall a. Storable a => Ptr (Mul a) -> IO (Mul a)
peek :: Ptr (Mul a) -> IO (Mul a)
$cpoke :: forall a. Storable a => Ptr (Mul a) -> Mul a -> IO ()
poke :: Ptr (Mul a) -> Mul a -> IO ()
Storable
    , Functor Mul
Foldable Mul
(Functor Mul, Foldable Mul) =>
(forall (f :: * -> *) a b.
 Applicative f =>
 (a -> f b) -> Mul a -> f (Mul b))
-> (forall (f :: * -> *) a.
    Applicative f =>
    Mul (f a) -> f (Mul a))
-> (forall (m :: * -> *) a b.
    Monad m =>
    (a -> m b) -> Mul a -> m (Mul b))
-> (forall (m :: * -> *) a. Monad m => Mul (m a) -> m (Mul a))
-> Traversable Mul
forall (t :: * -> *).
(Functor t, Foldable t) =>
(forall (f :: * -> *) a b.
 Applicative f =>
 (a -> f b) -> t a -> f (t b))
-> (forall (f :: * -> *) a. Applicative f => t (f a) -> f (t a))
-> (forall (m :: * -> *) a b.
    Monad m =>
    (a -> m b) -> t a -> m (t b))
-> (forall (m :: * -> *) a. Monad m => t (m a) -> m (t a))
-> Traversable t
forall (m :: * -> *) a. Monad m => Mul (m a) -> m (Mul a)
forall (f :: * -> *) a. Applicative f => Mul (f a) -> f (Mul a)
forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> Mul a -> m (Mul b)
forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> Mul a -> f (Mul b)
$ctraverse :: forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> Mul a -> f (Mul b)
traverse :: forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> Mul a -> f (Mul b)
$csequenceA :: forall (f :: * -> *) a. Applicative f => Mul (f a) -> f (Mul a)
sequenceA :: forall (f :: * -> *) a. Applicative f => Mul (f a) -> f (Mul a)
$cmapM :: forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> Mul a -> m (Mul b)
mapM :: forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> Mul a -> m (Mul b)
$csequence :: forall (m :: * -> *) a. Monad m => Mul (m a) -> m (Mul a)
sequence :: forall (m :: * -> *) a. Monad m => Mul (m a) -> m (Mul a)
Traversable
    , Typeable
    )

instance Semiring a => Semigroup (Mul a) where
  Mul a
a <> :: Mul a -> Mul a -> Mul a
<> Mul a
b = a -> Mul a
forall a. a -> Mul a
Mul (a
a a -> a -> a
forall a. Semiring a => a -> a -> a
* a
b)
  {-# INLINE (<>) #-}
  stimes :: forall b. Integral b => b -> Mul a -> Mul a
stimes b
n Mul a
x0 = case b -> b -> Ordering
forall a. Ord a => a -> a -> Ordering
compare b
n b
0 of
    Ordering
LT -> [Char] -> Mul a
forall a. HasCallStack => [Char] -> a
error [Char]
"stimes: negative multiplier"
    Ordering
EQ -> Mul a
forall a. Monoid a => a
mempty
    Ordering
GT -> Mul a -> b -> Mul a
forall {a} {t}. (Integral a, Monoid t) => t -> a -> t
f Mul a
x0 b
n
      where
        f :: t -> a -> t
f t
x a
y
          | a -> Bool
forall a. Integral a => a -> Bool
even a
y = t -> a -> t
f (t
x t -> t -> t
forall a. Monoid a => a -> a -> a
`mappend` t
x) (a
y a -> a -> a
forall a. Integral a => a -> a -> a
`quot` a
2)
          | a
y a -> a -> Bool
forall a. Eq a => a -> a -> Bool
== a
1 = t
x
          | Bool
otherwise = t -> a -> t -> t
forall {a} {t}. (Integral a, Monoid t) => t -> a -> t -> t
g (t
x t -> t -> t
forall a. Monoid a => a -> a -> a
`mappend` t
x) (a
y a -> a -> a
forall a. Integral a => a -> a -> a
`quot` a
2) t
x
        g :: t -> a -> t -> t
g t
x a
y t
z
          | a -> Bool
forall a. Integral a => a -> Bool
even a
y = t -> a -> t -> t
g (t
x t -> t -> t
forall a. Monoid a => a -> a -> a
`mappend` t
x) (a
y a -> a -> a
forall a. Integral a => a -> a -> a
`quot` a
2) t
z
          | a
y a -> a -> Bool
forall a. Eq a => a -> a -> Bool
== a
1 = t
x t -> t -> t
forall a. Monoid a => a -> a -> a
`mappend` t
z
          | Bool
otherwise = t -> a -> t -> t
g (t
x t -> t -> t
forall a. Monoid a => a -> a -> a
`mappend` t
x) (a
y a -> a -> a
forall a. Integral a => a -> a -> a
`quot` a
2) (t
x t -> t -> t
forall a. Monoid a => a -> a -> a
`mappend` t
z)
  {-# INLINE stimes #-}

instance Semiring a => Monoid (Mul a) where
  mempty :: Mul a
mempty = a -> Mul a
forall a. a -> Mul a
Mul a
forall a. Semiring a => a
one
  mappend :: Mul a -> Mul a -> Mul a
mappend = Mul a -> Mul a -> Mul a
forall a. Semigroup a => a -> a -> a
(<>)
  {-# INLINE mempty #-}
  {-# INLINE mappend #-}

-- | Provide Semiring and Ring for an arbitrary 'Num.Num'. It is useful with GHC 8.6+'s DerivingVia extension.
newtype WrappedNum a = WrapNum { forall a. WrappedNum a -> a
unwrapNum :: a }
  deriving
    ( WrappedNum a
WrappedNum a -> WrappedNum a -> Bounded (WrappedNum a)
forall a. a -> a -> Bounded a
forall a. Bounded a => WrappedNum a
$cminBound :: forall a. Bounded a => WrappedNum a
minBound :: WrappedNum a
$cmaxBound :: forall a. Bounded a => WrappedNum a
maxBound :: WrappedNum a
Bounded
    , Int -> WrappedNum a
WrappedNum a -> Int
WrappedNum a -> [WrappedNum a]
WrappedNum a -> WrappedNum a
WrappedNum a -> WrappedNum a -> [WrappedNum a]
WrappedNum a -> WrappedNum a -> WrappedNum a -> [WrappedNum a]
(WrappedNum a -> WrappedNum a)
-> (WrappedNum a -> WrappedNum a)
-> (Int -> WrappedNum a)
-> (WrappedNum a -> Int)
-> (WrappedNum a -> [WrappedNum a])
-> (WrappedNum a -> WrappedNum a -> [WrappedNum a])
-> (WrappedNum a -> WrappedNum a -> [WrappedNum a])
-> (WrappedNum a -> WrappedNum a -> WrappedNum a -> [WrappedNum a])
-> Enum (WrappedNum a)
forall a. Enum a => Int -> WrappedNum a
forall a. Enum a => WrappedNum a -> Int
forall a. Enum a => WrappedNum a -> [WrappedNum a]
forall a. Enum a => WrappedNum a -> WrappedNum a
forall a. Enum a => WrappedNum a -> WrappedNum a -> [WrappedNum a]
forall a.
Enum a =>
WrappedNum a -> WrappedNum a -> WrappedNum a -> [WrappedNum a]
forall a.
(a -> a)
-> (a -> a)
-> (Int -> a)
-> (a -> Int)
-> (a -> [a])
-> (a -> a -> [a])
-> (a -> a -> [a])
-> (a -> a -> a -> [a])
-> Enum a
$csucc :: forall a. Enum a => WrappedNum a -> WrappedNum a
succ :: WrappedNum a -> WrappedNum a
$cpred :: forall a. Enum a => WrappedNum a -> WrappedNum a
pred :: WrappedNum a -> WrappedNum a
$ctoEnum :: forall a. Enum a => Int -> WrappedNum a
toEnum :: Int -> WrappedNum a
$cfromEnum :: forall a. Enum a => WrappedNum a -> Int
fromEnum :: WrappedNum a -> Int
$cenumFrom :: forall a. Enum a => WrappedNum a -> [WrappedNum a]
enumFrom :: WrappedNum a -> [WrappedNum a]
$cenumFromThen :: forall a. Enum a => WrappedNum a -> WrappedNum a -> [WrappedNum a]
enumFromThen :: WrappedNum a -> WrappedNum a -> [WrappedNum a]
$cenumFromTo :: forall a. Enum a => WrappedNum a -> WrappedNum a -> [WrappedNum a]
enumFromTo :: WrappedNum a -> WrappedNum a -> [WrappedNum a]
$cenumFromThenTo :: forall a.
Enum a =>
WrappedNum a -> WrappedNum a -> WrappedNum a -> [WrappedNum a]
enumFromThenTo :: WrappedNum a -> WrappedNum a -> WrappedNum a -> [WrappedNum a]
Enum
    , WrappedNum a -> WrappedNum a -> Bool
(WrappedNum a -> WrappedNum a -> Bool)
-> (WrappedNum a -> WrappedNum a -> Bool) -> Eq (WrappedNum a)
forall a. Eq a => WrappedNum a -> WrappedNum a -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: forall a. Eq a => WrappedNum a -> WrappedNum a -> Bool
== :: WrappedNum a -> WrappedNum a -> Bool
$c/= :: forall a. Eq a => WrappedNum a -> WrappedNum a -> Bool
/= :: WrappedNum a -> WrappedNum a -> Bool
Eq
    , (forall m. Monoid m => WrappedNum m -> m)
-> (forall m a. Monoid m => (a -> m) -> WrappedNum a -> m)
-> (forall m a. Monoid m => (a -> m) -> WrappedNum a -> m)
-> (forall a b. (a -> b -> b) -> b -> WrappedNum a -> b)
-> (forall a b. (a -> b -> b) -> b -> WrappedNum a -> b)
-> (forall b a. (b -> a -> b) -> b -> WrappedNum a -> b)
-> (forall b a. (b -> a -> b) -> b -> WrappedNum a -> b)
-> (forall a. (a -> a -> a) -> WrappedNum a -> a)
-> (forall a. (a -> a -> a) -> WrappedNum a -> a)
-> (forall a. WrappedNum a -> [a])
-> (forall a. WrappedNum a -> Bool)
-> (forall a. WrappedNum a -> Int)
-> (forall a. Eq a => a -> WrappedNum a -> Bool)
-> (forall a. Ord a => WrappedNum a -> a)
-> (forall a. Ord a => WrappedNum a -> a)
-> (forall a. Num a => WrappedNum a -> a)
-> (forall a. Num a => WrappedNum a -> a)
-> Foldable WrappedNum
forall a. Eq a => a -> WrappedNum a -> Bool
forall a. Num a => WrappedNum a -> a
forall a. Ord a => WrappedNum a -> a
forall m. Monoid m => WrappedNum m -> m
forall a. WrappedNum a -> Bool
forall a. WrappedNum a -> Int
forall a. WrappedNum a -> [a]
forall a. (a -> a -> a) -> WrappedNum a -> a
forall m a. Monoid m => (a -> m) -> WrappedNum a -> m
forall b a. (b -> a -> b) -> b -> WrappedNum a -> b
forall a b. (a -> b -> b) -> b -> WrappedNum a -> b
forall (t :: * -> *).
(forall m. Monoid m => t m -> m)
-> (forall m a. Monoid m => (a -> m) -> t a -> m)
-> (forall m a. Monoid m => (a -> m) -> t a -> m)
-> (forall a b. (a -> b -> b) -> b -> t a -> b)
-> (forall a b. (a -> b -> b) -> b -> t a -> b)
-> (forall b a. (b -> a -> b) -> b -> t a -> b)
-> (forall b a. (b -> a -> b) -> b -> t a -> b)
-> (forall a. (a -> a -> a) -> t a -> a)
-> (forall a. (a -> a -> a) -> t a -> a)
-> (forall a. t a -> [a])
-> (forall a. t a -> Bool)
-> (forall a. t a -> Int)
-> (forall a. Eq a => a -> t a -> Bool)
-> (forall a. Ord a => t a -> a)
-> (forall a. Ord a => t a -> a)
-> (forall a. Num a => t a -> a)
-> (forall a. Num a => t a -> a)
-> Foldable t
$cfold :: forall m. Monoid m => WrappedNum m -> m
fold :: forall m. Monoid m => WrappedNum m -> m
$cfoldMap :: forall m a. Monoid m => (a -> m) -> WrappedNum a -> m
foldMap :: forall m a. Monoid m => (a -> m) -> WrappedNum a -> m
$cfoldMap' :: forall m a. Monoid m => (a -> m) -> WrappedNum a -> m
foldMap' :: forall m a. Monoid m => (a -> m) -> WrappedNum a -> m
$cfoldr :: forall a b. (a -> b -> b) -> b -> WrappedNum a -> b
foldr :: forall a b. (a -> b -> b) -> b -> WrappedNum a -> b
$cfoldr' :: forall a b. (a -> b -> b) -> b -> WrappedNum a -> b
foldr' :: forall a b. (a -> b -> b) -> b -> WrappedNum a -> b
$cfoldl :: forall b a. (b -> a -> b) -> b -> WrappedNum a -> b
foldl :: forall b a. (b -> a -> b) -> b -> WrappedNum a -> b
$cfoldl' :: forall b a. (b -> a -> b) -> b -> WrappedNum a -> b
foldl' :: forall b a. (b -> a -> b) -> b -> WrappedNum a -> b
$cfoldr1 :: forall a. (a -> a -> a) -> WrappedNum a -> a
foldr1 :: forall a. (a -> a -> a) -> WrappedNum a -> a
$cfoldl1 :: forall a. (a -> a -> a) -> WrappedNum a -> a
foldl1 :: forall a. (a -> a -> a) -> WrappedNum a -> a
$ctoList :: forall a. WrappedNum a -> [a]
toList :: forall a. WrappedNum a -> [a]
$cnull :: forall a. WrappedNum a -> Bool
null :: forall a. WrappedNum a -> Bool
$clength :: forall a. WrappedNum a -> Int
length :: forall a. WrappedNum a -> Int
$celem :: forall a. Eq a => a -> WrappedNum a -> Bool
elem :: forall a. Eq a => a -> WrappedNum a -> Bool
$cmaximum :: forall a. Ord a => WrappedNum a -> a
maximum :: forall a. Ord a => WrappedNum a -> a
$cminimum :: forall a. Ord a => WrappedNum a -> a
minimum :: forall a. Ord a => WrappedNum a -> a
$csum :: forall a. Num a => WrappedNum a -> a
sum :: forall a. Num a => WrappedNum a -> a
$cproduct :: forall a. Num a => WrappedNum a -> a
product :: forall a. Num a => WrappedNum a -> a
Foldable
    , Num (WrappedNum a)
Num (WrappedNum a) =>
(WrappedNum a -> WrappedNum a -> WrappedNum a)
-> (WrappedNum a -> WrappedNum a)
-> (Rational -> WrappedNum a)
-> Fractional (WrappedNum a)
Rational -> WrappedNum a
WrappedNum a -> WrappedNum a
WrappedNum a -> WrappedNum a -> WrappedNum a
forall a. Fractional a => Num (WrappedNum a)
forall a. Fractional a => Rational -> WrappedNum a
forall a. Fractional a => WrappedNum a -> WrappedNum a
forall a.
Fractional a =>
WrappedNum a -> WrappedNum a -> WrappedNum a
forall a.
Num a =>
(a -> a -> a) -> (a -> a) -> (Rational -> a) -> Fractional a
$c/ :: forall a.
Fractional a =>
WrappedNum a -> WrappedNum a -> WrappedNum a
/ :: WrappedNum a -> WrappedNum a -> WrappedNum a
$crecip :: forall a. Fractional a => WrappedNum a -> WrappedNum a
recip :: WrappedNum a -> WrappedNum a
$cfromRational :: forall a. Fractional a => Rational -> WrappedNum a
fromRational :: Rational -> WrappedNum a
Fractional
    , (forall a b. (a -> b) -> WrappedNum a -> WrappedNum b)
-> (forall a b. a -> WrappedNum b -> WrappedNum a)
-> Functor WrappedNum
forall a b. a -> WrappedNum b -> WrappedNum a
forall a b. (a -> b) -> WrappedNum a -> WrappedNum b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
$cfmap :: forall a b. (a -> b) -> WrappedNum a -> WrappedNum b
fmap :: forall a b. (a -> b) -> WrappedNum a -> WrappedNum b
$c<$ :: forall a b. a -> WrappedNum b -> WrappedNum a
<$ :: forall a b. a -> WrappedNum b -> WrappedNum a
Functor
    , (forall x. WrappedNum a -> Rep (WrappedNum a) x)
-> (forall x. Rep (WrappedNum a) x -> WrappedNum a)
-> Generic (WrappedNum a)
forall x. Rep (WrappedNum a) x -> WrappedNum a
forall x. WrappedNum a -> Rep (WrappedNum a) x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall a x. Rep (WrappedNum a) x -> WrappedNum a
forall a x. WrappedNum a -> Rep (WrappedNum a) x
$cfrom :: forall a x. WrappedNum a -> Rep (WrappedNum a) x
from :: forall x. WrappedNum a -> Rep (WrappedNum a) x
$cto :: forall a x. Rep (WrappedNum a) x -> WrappedNum a
to :: forall x. Rep (WrappedNum a) x -> WrappedNum a
Generic
    , (forall a. WrappedNum a -> Rep1 WrappedNum a)
-> (forall a. Rep1 WrappedNum a -> WrappedNum a)
-> Generic1 WrappedNum
forall a. Rep1 WrappedNum a -> WrappedNum a
forall a. WrappedNum a -> Rep1 WrappedNum a
forall k (f :: k -> *).
(forall (a :: k). f a -> Rep1 f a)
-> (forall (a :: k). Rep1 f a -> f a) -> Generic1 f
$cfrom1 :: forall a. WrappedNum a -> Rep1 WrappedNum a
from1 :: forall a. WrappedNum a -> Rep1 WrappedNum a
$cto1 :: forall a. Rep1 WrappedNum a -> WrappedNum a
to1 :: forall a. Rep1 WrappedNum a -> WrappedNum a
Generic1
    , Integer -> WrappedNum a
WrappedNum a -> WrappedNum a
WrappedNum a -> WrappedNum a -> WrappedNum a
(WrappedNum a -> WrappedNum a -> WrappedNum a)
-> (WrappedNum a -> WrappedNum a -> WrappedNum a)
-> (WrappedNum a -> WrappedNum a -> WrappedNum a)
-> (WrappedNum a -> WrappedNum a)
-> (WrappedNum a -> WrappedNum a)
-> (WrappedNum a -> WrappedNum a)
-> (Integer -> WrappedNum a)
-> Num (WrappedNum a)
forall a. Num a => Integer -> WrappedNum a
forall a. Num a => WrappedNum a -> WrappedNum a
forall a. Num a => WrappedNum a -> WrappedNum a -> WrappedNum a
forall a.
(a -> a -> a)
-> (a -> a -> a)
-> (a -> a -> a)
-> (a -> a)
-> (a -> a)
-> (a -> a)
-> (Integer -> a)
-> Num a
$c+ :: forall a. Num a => WrappedNum a -> WrappedNum a -> WrappedNum a
+ :: WrappedNum a -> WrappedNum a -> WrappedNum a
$c- :: forall a. Num a => WrappedNum a -> WrappedNum a -> WrappedNum a
- :: WrappedNum a -> WrappedNum a -> WrappedNum a
$c* :: forall a. Num a => WrappedNum a -> WrappedNum a -> WrappedNum a
* :: WrappedNum a -> WrappedNum a -> WrappedNum a
$cnegate :: forall a. Num a => WrappedNum a -> WrappedNum a
negate :: WrappedNum a -> WrappedNum a
$cabs :: forall a. Num a => WrappedNum a -> WrappedNum a
abs :: WrappedNum a -> WrappedNum a
$csignum :: forall a. Num a => WrappedNum a -> WrappedNum a
signum :: WrappedNum a -> WrappedNum a
$cfromInteger :: forall a. Num a => Integer -> WrappedNum a
fromInteger :: Integer -> WrappedNum a
Num.Num
    , Eq (WrappedNum a)
Eq (WrappedNum a) =>
(WrappedNum a -> WrappedNum a -> Ordering)
-> (WrappedNum a -> WrappedNum a -> Bool)
-> (WrappedNum a -> WrappedNum a -> Bool)
-> (WrappedNum a -> WrappedNum a -> Bool)
-> (WrappedNum a -> WrappedNum a -> Bool)
-> (WrappedNum a -> WrappedNum a -> WrappedNum a)
-> (WrappedNum a -> WrappedNum a -> WrappedNum a)
-> Ord (WrappedNum a)
WrappedNum a -> WrappedNum a -> Bool
WrappedNum a -> WrappedNum a -> Ordering
WrappedNum a -> WrappedNum a -> WrappedNum a
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
forall a. Ord a => Eq (WrappedNum a)
forall a. Ord a => WrappedNum a -> WrappedNum a -> Bool
forall a. Ord a => WrappedNum a -> WrappedNum a -> Ordering
forall a. Ord a => WrappedNum a -> WrappedNum a -> WrappedNum a
$ccompare :: forall a. Ord a => WrappedNum a -> WrappedNum a -> Ordering
compare :: WrappedNum a -> WrappedNum a -> Ordering
$c< :: forall a. Ord a => WrappedNum a -> WrappedNum a -> Bool
< :: WrappedNum a -> WrappedNum a -> Bool
$c<= :: forall a. Ord a => WrappedNum a -> WrappedNum a -> Bool
<= :: WrappedNum a -> WrappedNum a -> Bool
$c> :: forall a. Ord a => WrappedNum a -> WrappedNum a -> Bool
> :: WrappedNum a -> WrappedNum a -> Bool
$c>= :: forall a. Ord a => WrappedNum a -> WrappedNum a -> Bool
>= :: WrappedNum a -> WrappedNum a -> Bool
$cmax :: forall a. Ord a => WrappedNum a -> WrappedNum a -> WrappedNum a
max :: WrappedNum a -> WrappedNum a -> WrappedNum a
$cmin :: forall a. Ord a => WrappedNum a -> WrappedNum a -> WrappedNum a
min :: WrappedNum a -> WrappedNum a -> WrappedNum a
Ord
    , ReadPrec [WrappedNum a]
ReadPrec (WrappedNum a)
Int -> ReadS (WrappedNum a)
ReadS [WrappedNum a]
(Int -> ReadS (WrappedNum a))
-> ReadS [WrappedNum a]
-> ReadPrec (WrappedNum a)
-> ReadPrec [WrappedNum a]
-> Read (WrappedNum a)
forall a. Read a => ReadPrec [WrappedNum a]
forall a. Read a => ReadPrec (WrappedNum a)
forall a. Read a => Int -> ReadS (WrappedNum a)
forall a. Read a => ReadS [WrappedNum a]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
$creadsPrec :: forall a. Read a => Int -> ReadS (WrappedNum a)
readsPrec :: Int -> ReadS (WrappedNum a)
$creadList :: forall a. Read a => ReadS [WrappedNum a]
readList :: ReadS [WrappedNum a]
$creadPrec :: forall a. Read a => ReadPrec (WrappedNum a)
readPrec :: ReadPrec (WrappedNum a)
$creadListPrec :: forall a. Read a => ReadPrec [WrappedNum a]
readListPrec :: ReadPrec [WrappedNum a]
Read
    , Num (WrappedNum a)
Ord (WrappedNum a)
(Num (WrappedNum a), Ord (WrappedNum a)) =>
(WrappedNum a -> Rational) -> Real (WrappedNum a)
WrappedNum a -> Rational
forall a. (Num a, Ord a) => (a -> Rational) -> Real a
forall a. Real a => Num (WrappedNum a)
forall a. Real a => Ord (WrappedNum a)
forall a. Real a => WrappedNum a -> Rational
$ctoRational :: forall a. Real a => WrappedNum a -> Rational
toRational :: WrappedNum a -> Rational
Real
    , Fractional (WrappedNum a)
Real (WrappedNum a)
(Real (WrappedNum a), Fractional (WrappedNum a)) =>
(forall b. Integral b => WrappedNum a -> (b, WrappedNum a))
-> (forall b. Integral b => WrappedNum a -> b)
-> (forall b. Integral b => WrappedNum a -> b)
-> (forall b. Integral b => WrappedNum a -> b)
-> (forall b. Integral b => WrappedNum a -> b)
-> RealFrac (WrappedNum a)
forall b. Integral b => WrappedNum a -> b
forall b. Integral b => WrappedNum a -> (b, WrappedNum a)
forall a.
(Real a, Fractional a) =>
(forall b. Integral b => a -> (b, a))
-> (forall b. Integral b => a -> b)
-> (forall b. Integral b => a -> b)
-> (forall b. Integral b => a -> b)
-> (forall b. Integral b => a -> b)
-> RealFrac a
forall a. RealFrac a => Fractional (WrappedNum a)
forall a. RealFrac a => Real (WrappedNum a)
forall a b. (RealFrac a, Integral b) => WrappedNum a -> b
forall a b.
(RealFrac a, Integral b) =>
WrappedNum a -> (b, WrappedNum a)
$cproperFraction :: forall a b.
(RealFrac a, Integral b) =>
WrappedNum a -> (b, WrappedNum a)
properFraction :: forall b. Integral b => WrappedNum a -> (b, WrappedNum a)
$ctruncate :: forall a b. (RealFrac a, Integral b) => WrappedNum a -> b
truncate :: forall b. Integral b => WrappedNum a -> b
$cround :: forall a b. (RealFrac a, Integral b) => WrappedNum a -> b
round :: forall b. Integral b => WrappedNum a -> b
$cceiling :: forall a b. (RealFrac a, Integral b) => WrappedNum a -> b
ceiling :: forall b. Integral b => WrappedNum a -> b
$cfloor :: forall a b. (RealFrac a, Integral b) => WrappedNum a -> b
floor :: forall b. Integral b => WrappedNum a -> b
RealFrac
    , Int -> WrappedNum a -> ShowS
[WrappedNum a] -> ShowS
WrappedNum a -> [Char]
(Int -> WrappedNum a -> ShowS)
-> (WrappedNum a -> [Char])
-> ([WrappedNum a] -> ShowS)
-> Show (WrappedNum a)
forall a. Show a => Int -> WrappedNum a -> ShowS
forall a. Show a => [WrappedNum a] -> ShowS
forall a. Show a => WrappedNum a -> [Char]
forall a.
(Int -> a -> ShowS) -> (a -> [Char]) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: forall a. Show a => Int -> WrappedNum a -> ShowS
showsPrec :: Int -> WrappedNum a -> ShowS
$cshow :: forall a. Show a => WrappedNum a -> [Char]
show :: WrappedNum a -> [Char]
$cshowList :: forall a. Show a => [WrappedNum a] -> ShowS
showList :: [WrappedNum a] -> ShowS
Show
    , Ptr (WrappedNum a) -> IO (WrappedNum a)
Ptr (WrappedNum a) -> Int -> IO (WrappedNum a)
Ptr (WrappedNum a) -> Int -> WrappedNum a -> IO ()
Ptr (WrappedNum a) -> WrappedNum a -> IO ()
WrappedNum a -> Int
(WrappedNum a -> Int)
-> (WrappedNum a -> Int)
-> (Ptr (WrappedNum a) -> Int -> IO (WrappedNum a))
-> (Ptr (WrappedNum a) -> Int -> WrappedNum a -> IO ())
-> (forall b. Ptr b -> Int -> IO (WrappedNum a))
-> (forall b. Ptr b -> Int -> WrappedNum a -> IO ())
-> (Ptr (WrappedNum a) -> IO (WrappedNum a))
-> (Ptr (WrappedNum a) -> WrappedNum a -> IO ())
-> Storable (WrappedNum a)
forall b. Ptr b -> Int -> IO (WrappedNum a)
forall b. Ptr b -> Int -> WrappedNum a -> IO ()
forall a. Storable a => Ptr (WrappedNum a) -> IO (WrappedNum a)
forall a.
Storable a =>
Ptr (WrappedNum a) -> Int -> IO (WrappedNum a)
forall a.
Storable a =>
Ptr (WrappedNum a) -> Int -> WrappedNum a -> IO ()
forall a. Storable a => Ptr (WrappedNum a) -> WrappedNum a -> IO ()
forall a. Storable a => WrappedNum a -> Int
forall a b. Storable a => Ptr b -> Int -> IO (WrappedNum a)
forall a b. Storable a => Ptr b -> Int -> WrappedNum a -> IO ()
forall a.
(a -> Int)
-> (a -> Int)
-> (Ptr a -> Int -> IO a)
-> (Ptr a -> Int -> a -> IO ())
-> (forall b. Ptr b -> Int -> IO a)
-> (forall b. Ptr b -> Int -> a -> IO ())
-> (Ptr a -> IO a)
-> (Ptr a -> a -> IO ())
-> Storable a
$csizeOf :: forall a. Storable a => WrappedNum a -> Int
sizeOf :: WrappedNum a -> Int
$calignment :: forall a. Storable a => WrappedNum a -> Int
alignment :: WrappedNum a -> Int
$cpeekElemOff :: forall a.
Storable a =>
Ptr (WrappedNum a) -> Int -> IO (WrappedNum a)
peekElemOff :: Ptr (WrappedNum a) -> Int -> IO (WrappedNum a)
$cpokeElemOff :: forall a.
Storable a =>
Ptr (WrappedNum a) -> Int -> WrappedNum a -> IO ()
pokeElemOff :: Ptr (WrappedNum a) -> Int -> WrappedNum a -> IO ()
$cpeekByteOff :: forall a b. Storable a => Ptr b -> Int -> IO (WrappedNum a)
peekByteOff :: forall b. Ptr b -> Int -> IO (WrappedNum a)
$cpokeByteOff :: forall a b. Storable a => Ptr b -> Int -> WrappedNum a -> IO ()
pokeByteOff :: forall b. Ptr b -> Int -> WrappedNum a -> IO ()
$cpeek :: forall a. Storable a => Ptr (WrappedNum a) -> IO (WrappedNum a)
peek :: Ptr (WrappedNum a) -> IO (WrappedNum a)
$cpoke :: forall a. Storable a => Ptr (WrappedNum a) -> WrappedNum a -> IO ()
poke :: Ptr (WrappedNum a) -> WrappedNum a -> IO ()
Storable
    , Functor WrappedNum
Foldable WrappedNum
(Functor WrappedNum, Foldable WrappedNum) =>
(forall (f :: * -> *) a b.
 Applicative f =>
 (a -> f b) -> WrappedNum a -> f (WrappedNum b))
-> (forall (f :: * -> *) a.
    Applicative f =>
    WrappedNum (f a) -> f (WrappedNum a))
-> (forall (m :: * -> *) a b.
    Monad m =>
    (a -> m b) -> WrappedNum a -> m (WrappedNum b))
-> (forall (m :: * -> *) a.
    Monad m =>
    WrappedNum (m a) -> m (WrappedNum a))
-> Traversable WrappedNum
forall (t :: * -> *).
(Functor t, Foldable t) =>
(forall (f :: * -> *) a b.
 Applicative f =>
 (a -> f b) -> t a -> f (t b))
-> (forall (f :: * -> *) a. Applicative f => t (f a) -> f (t a))
-> (forall (m :: * -> *) a b.
    Monad m =>
    (a -> m b) -> t a -> m (t b))
-> (forall (m :: * -> *) a. Monad m => t (m a) -> m (t a))
-> Traversable t
forall (m :: * -> *) a.
Monad m =>
WrappedNum (m a) -> m (WrappedNum a)
forall (f :: * -> *) a.
Applicative f =>
WrappedNum (f a) -> f (WrappedNum a)
forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> WrappedNum a -> m (WrappedNum b)
forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> WrappedNum a -> f (WrappedNum b)
$ctraverse :: forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> WrappedNum a -> f (WrappedNum b)
traverse :: forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> WrappedNum a -> f (WrappedNum b)
$csequenceA :: forall (f :: * -> *) a.
Applicative f =>
WrappedNum (f a) -> f (WrappedNum a)
sequenceA :: forall (f :: * -> *) a.
Applicative f =>
WrappedNum (f a) -> f (WrappedNum a)
$cmapM :: forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> WrappedNum a -> m (WrappedNum b)
mapM :: forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> WrappedNum a -> m (WrappedNum b)
$csequence :: forall (m :: * -> *) a.
Monad m =>
WrappedNum (m a) -> m (WrappedNum a)
sequence :: forall (m :: * -> *) a.
Monad m =>
WrappedNum (m a) -> m (WrappedNum a)
Traversable
    , Typeable
    , Eq (WrappedNum a)
WrappedNum a
Eq (WrappedNum a) =>
(WrappedNum a -> WrappedNum a -> WrappedNum a)
-> (WrappedNum a -> WrappedNum a -> WrappedNum a)
-> (WrappedNum a -> WrappedNum a -> WrappedNum a)
-> (WrappedNum a -> WrappedNum a)
-> (WrappedNum a -> Int -> WrappedNum a)
-> (WrappedNum a -> Int -> WrappedNum a)
-> WrappedNum a
-> (Int -> WrappedNum a)
-> (WrappedNum a -> Int -> WrappedNum a)
-> (WrappedNum a -> Int -> WrappedNum a)
-> (WrappedNum a -> Int -> WrappedNum a)
-> (WrappedNum a -> Int -> Bool)
-> (WrappedNum a -> Maybe Int)
-> (WrappedNum a -> Int)
-> (WrappedNum a -> Bool)
-> (WrappedNum a -> Int -> WrappedNum a)
-> (WrappedNum a -> Int -> WrappedNum a)
-> (WrappedNum a -> Int -> WrappedNum a)
-> (WrappedNum a -> Int -> WrappedNum a)
-> (WrappedNum a -> Int -> WrappedNum a)
-> (WrappedNum a -> Int -> WrappedNum a)
-> (WrappedNum a -> Int)
-> Bits (WrappedNum a)
Int -> WrappedNum a
WrappedNum a -> Bool
WrappedNum a -> Int
WrappedNum a -> Maybe Int
WrappedNum a -> WrappedNum a
WrappedNum a -> Int -> Bool
WrappedNum a -> Int -> WrappedNum a
WrappedNum a -> WrappedNum a -> WrappedNum a
forall a.
Eq a =>
(a -> a -> a)
-> (a -> a -> a)
-> (a -> a -> a)
-> (a -> a)
-> (a -> Int -> a)
-> (a -> Int -> a)
-> a
-> (Int -> a)
-> (a -> Int -> a)
-> (a -> Int -> a)
-> (a -> Int -> a)
-> (a -> Int -> Bool)
-> (a -> Maybe Int)
-> (a -> Int)
-> (a -> Bool)
-> (a -> Int -> a)
-> (a -> Int -> a)
-> (a -> Int -> a)
-> (a -> Int -> a)
-> (a -> Int -> a)
-> (a -> Int -> a)
-> (a -> Int)
-> Bits a
forall a. Bits a => Eq (WrappedNum a)
forall a. Bits a => WrappedNum a
forall a. Bits a => Int -> WrappedNum a
forall a. Bits a => WrappedNum a -> Bool
forall a. Bits a => WrappedNum a -> Int
forall a. Bits a => WrappedNum a -> Maybe Int
forall a. Bits a => WrappedNum a -> WrappedNum a
forall a. Bits a => WrappedNum a -> Int -> Bool
forall a. Bits a => WrappedNum a -> Int -> WrappedNum a
forall a. Bits a => WrappedNum a -> WrappedNum a -> WrappedNum a
$c.&. :: forall a. Bits a => WrappedNum a -> WrappedNum a -> WrappedNum a
.&. :: WrappedNum a -> WrappedNum a -> WrappedNum a
$c.|. :: forall a. Bits a => WrappedNum a -> WrappedNum a -> WrappedNum a
.|. :: WrappedNum a -> WrappedNum a -> WrappedNum a
$cxor :: forall a. Bits a => WrappedNum a -> WrappedNum a -> WrappedNum a
xor :: WrappedNum a -> WrappedNum a -> WrappedNum a
$ccomplement :: forall a. Bits a => WrappedNum a -> WrappedNum a
complement :: WrappedNum a -> WrappedNum a
$cshift :: forall a. Bits a => WrappedNum a -> Int -> WrappedNum a
shift :: WrappedNum a -> Int -> WrappedNum a
$crotate :: forall a. Bits a => WrappedNum a -> Int -> WrappedNum a
rotate :: WrappedNum a -> Int -> WrappedNum a
$czeroBits :: forall a. Bits a => WrappedNum a
zeroBits :: WrappedNum a
$cbit :: forall a. Bits a => Int -> WrappedNum a
bit :: Int -> WrappedNum a
$csetBit :: forall a. Bits a => WrappedNum a -> Int -> WrappedNum a
setBit :: WrappedNum a -> Int -> WrappedNum a
$cclearBit :: forall a. Bits a => WrappedNum a -> Int -> WrappedNum a
clearBit :: WrappedNum a -> Int -> WrappedNum a
$ccomplementBit :: forall a. Bits a => WrappedNum a -> Int -> WrappedNum a
complementBit :: WrappedNum a -> Int -> WrappedNum a
$ctestBit :: forall a. Bits a => WrappedNum a -> Int -> Bool
testBit :: WrappedNum a -> Int -> Bool
$cbitSizeMaybe :: forall a. Bits a => WrappedNum a -> Maybe Int
bitSizeMaybe :: WrappedNum a -> Maybe Int
$cbitSize :: forall a. Bits a => WrappedNum a -> Int
bitSize :: WrappedNum a -> Int
$cisSigned :: forall a. Bits a => WrappedNum a -> Bool
isSigned :: WrappedNum a -> Bool
$cshiftL :: forall a. Bits a => WrappedNum a -> Int -> WrappedNum a
shiftL :: WrappedNum a -> Int -> WrappedNum a
$cunsafeShiftL :: forall a. Bits a => WrappedNum a -> Int -> WrappedNum a
unsafeShiftL :: WrappedNum a -> Int -> WrappedNum a
$cshiftR :: forall a. Bits a => WrappedNum a -> Int -> WrappedNum a
shiftR :: WrappedNum a -> Int -> WrappedNum a
$cunsafeShiftR :: forall a. Bits a => WrappedNum a -> Int -> WrappedNum a
unsafeShiftR :: WrappedNum a -> Int -> WrappedNum a
$crotateL :: forall a. Bits a => WrappedNum a -> Int -> WrappedNum a
rotateL :: WrappedNum a -> Int -> WrappedNum a
$crotateR :: forall a. Bits a => WrappedNum a -> Int -> WrappedNum a
rotateR :: WrappedNum a -> Int -> WrappedNum a
$cpopCount :: forall a. Bits a => WrappedNum a -> Int
popCount :: WrappedNum a -> Int
Bits
    )

instance Num.Num a => Semiring (WrappedNum a) where
  plus :: WrappedNum a -> WrappedNum a -> WrappedNum a
plus  = WrappedNum a -> WrappedNum a -> WrappedNum a
forall a. Num a => a -> a -> a
(Num.+)
  zero :: WrappedNum a
zero  = WrappedNum a
0
  times :: WrappedNum a -> WrappedNum a -> WrappedNum a
times = WrappedNum a -> WrappedNum a -> WrappedNum a
forall a. Num a => a -> a -> a
(Num.*)
  one :: WrappedNum a
one   = WrappedNum a
1
  fromNatural :: Natural -> WrappedNum a
fromNatural = Natural -> WrappedNum a
forall a b. (Integral a, Num b) => a -> b
Real.fromIntegral

instance Num.Num a => Ring (WrappedNum a) where
  negate :: WrappedNum a -> WrappedNum a
negate = WrappedNum a -> WrappedNum a
forall a. Num a => a -> a
Num.negate

-- | 'Mod2' represents the integers mod 2.
--
--   It is useful in the computing of <https://en.wikipedia.org/wiki/Zhegalkin_polynomial Zhegalkin polynomials>.
newtype Mod2 = Mod2 { Mod2 -> Bool
getMod2 :: Bool }
  deriving
    ( Mod2
Mod2 -> Mod2 -> Bounded Mod2
forall a. a -> a -> Bounded a
$cminBound :: Mod2
minBound :: Mod2
$cmaxBound :: Mod2
maxBound :: Mod2
Bounded
    , Int -> Mod2
Mod2 -> Int
Mod2 -> [Mod2]
Mod2 -> Mod2
Mod2 -> Mod2 -> [Mod2]
Mod2 -> Mod2 -> Mod2 -> [Mod2]
(Mod2 -> Mod2)
-> (Mod2 -> Mod2)
-> (Int -> Mod2)
-> (Mod2 -> Int)
-> (Mod2 -> [Mod2])
-> (Mod2 -> Mod2 -> [Mod2])
-> (Mod2 -> Mod2 -> [Mod2])
-> (Mod2 -> Mod2 -> Mod2 -> [Mod2])
-> Enum Mod2
forall a.
(a -> a)
-> (a -> a)
-> (Int -> a)
-> (a -> Int)
-> (a -> [a])
-> (a -> a -> [a])
-> (a -> a -> [a])
-> (a -> a -> a -> [a])
-> Enum a
$csucc :: Mod2 -> Mod2
succ :: Mod2 -> Mod2
$cpred :: Mod2 -> Mod2
pred :: Mod2 -> Mod2
$ctoEnum :: Int -> Mod2
toEnum :: Int -> Mod2
$cfromEnum :: Mod2 -> Int
fromEnum :: Mod2 -> Int
$cenumFrom :: Mod2 -> [Mod2]
enumFrom :: Mod2 -> [Mod2]
$cenumFromThen :: Mod2 -> Mod2 -> [Mod2]
enumFromThen :: Mod2 -> Mod2 -> [Mod2]
$cenumFromTo :: Mod2 -> Mod2 -> [Mod2]
enumFromTo :: Mod2 -> Mod2 -> [Mod2]
$cenumFromThenTo :: Mod2 -> Mod2 -> Mod2 -> [Mod2]
enumFromThenTo :: Mod2 -> Mod2 -> Mod2 -> [Mod2]
Enum
    , Mod2 -> Mod2 -> Bool
(Mod2 -> Mod2 -> Bool) -> (Mod2 -> Mod2 -> Bool) -> Eq Mod2
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Mod2 -> Mod2 -> Bool
== :: Mod2 -> Mod2 -> Bool
$c/= :: Mod2 -> Mod2 -> Bool
/= :: Mod2 -> Mod2 -> Bool
Eq
    , Eq Mod2
Eq Mod2 =>
(Mod2 -> Mod2 -> Ordering)
-> (Mod2 -> Mod2 -> Bool)
-> (Mod2 -> Mod2 -> Bool)
-> (Mod2 -> Mod2 -> Bool)
-> (Mod2 -> Mod2 -> Bool)
-> (Mod2 -> Mod2 -> Mod2)
-> (Mod2 -> Mod2 -> Mod2)
-> Ord Mod2
Mod2 -> Mod2 -> Bool
Mod2 -> Mod2 -> Ordering
Mod2 -> Mod2 -> Mod2
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: Mod2 -> Mod2 -> Ordering
compare :: Mod2 -> Mod2 -> Ordering
$c< :: Mod2 -> Mod2 -> Bool
< :: Mod2 -> Mod2 -> Bool
$c<= :: Mod2 -> Mod2 -> Bool
<= :: Mod2 -> Mod2 -> Bool
$c> :: Mod2 -> Mod2 -> Bool
> :: Mod2 -> Mod2 -> Bool
$c>= :: Mod2 -> Mod2 -> Bool
>= :: Mod2 -> Mod2 -> Bool
$cmax :: Mod2 -> Mod2 -> Mod2
max :: Mod2 -> Mod2 -> Mod2
$cmin :: Mod2 -> Mod2 -> Mod2
min :: Mod2 -> Mod2 -> Mod2
Ord
    , ReadPrec [Mod2]
ReadPrec Mod2
Int -> ReadS Mod2
ReadS [Mod2]
(Int -> ReadS Mod2)
-> ReadS [Mod2] -> ReadPrec Mod2 -> ReadPrec [Mod2] -> Read Mod2
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
$creadsPrec :: Int -> ReadS Mod2
readsPrec :: Int -> ReadS Mod2
$creadList :: ReadS [Mod2]
readList :: ReadS [Mod2]
$creadPrec :: ReadPrec Mod2
readPrec :: ReadPrec Mod2
$creadListPrec :: ReadPrec [Mod2]
readListPrec :: ReadPrec [Mod2]
Read
    , Int -> Mod2 -> ShowS
[Mod2] -> ShowS
Mod2 -> [Char]
(Int -> Mod2 -> ShowS)
-> (Mod2 -> [Char]) -> ([Mod2] -> ShowS) -> Show Mod2
forall a.
(Int -> a -> ShowS) -> (a -> [Char]) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Mod2 -> ShowS
showsPrec :: Int -> Mod2 -> ShowS
$cshow :: Mod2 -> [Char]
show :: Mod2 -> [Char]
$cshowList :: [Mod2] -> ShowS
showList :: [Mod2] -> ShowS
Show
    , (forall x. Mod2 -> Rep Mod2 x)
-> (forall x. Rep Mod2 x -> Mod2) -> Generic Mod2
forall x. Rep Mod2 x -> Mod2
forall x. Mod2 -> Rep Mod2 x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. Mod2 -> Rep Mod2 x
from :: forall x. Mod2 -> Rep Mod2 x
$cto :: forall x. Rep Mod2 x -> Mod2
to :: forall x. Rep Mod2 x -> Mod2
Generic
    )

instance Semiring Mod2 where
  plus :: Mod2 -> Mod2 -> Mod2
plus (Mod2 Bool
x) (Mod2 Bool
y) = Bool -> Mod2
Mod2 (Bool
x Bool -> Bool -> Bool
forall a. Bits a => a -> a -> a
`xor` Bool
y)
  times :: Mod2 -> Mod2 -> Mod2
times (Mod2 Bool
x) (Mod2 Bool
y) = Bool -> Mod2
Mod2 (Bool
x Bool -> Bool -> Bool
&& Bool
y)
  zero :: Mod2
zero = Bool -> Mod2
Mod2 Bool
False
  one :: Mod2
one = Bool -> Mod2
Mod2 Bool
True

instance Ring Mod2 where
  negate :: Mod2 -> Mod2
negate = Mod2 -> Mod2
forall a. a -> a
id
  {-# INLINE negate #-}


{--------------------------------------------------------------------
  Classes
--------------------------------------------------------------------}

-- | The class of semirings (types with two binary
-- operations and two respective identities). One
-- can think of a semiring as two monoids of the same
-- underlying type, with the first being commutative.
-- In the documentation, you will often see the first
-- monoid being referred to as @additive@, and the second
-- monoid being referred to as @multiplicative@, a typical
-- convention when talking about semirings.
--
-- For any type R with a 'Num.Num'
-- instance, the additive monoid is (R, 'Prelude.+', 0)
-- and the multiplicative monoid is (R, 'Prelude.*', 1).
--
-- For 'Prelude.Bool', the additive monoid is ('Prelude.Bool', 'Prelude.||', 'Prelude.False')
-- and the multiplicative monoid is ('Prelude.Bool', 'Prelude.&&', 'Prelude.True').
--
-- Instances should satisfy the following laws:
--
-- [/additive left identity/]
--     @'zero' '+' x = x@
-- [/additive right identity/]
--     @x '+' 'zero' = x@
-- [/additive associativity/]
--     @x '+' (y '+' z) = (x '+' y) '+' z@
-- [/additive commutativity/]
--     @x '+' y = y '+' x@
-- [/multiplicative left identity/]
--     @'one' '*' x = x@
-- [/multiplicative right identity/]
--     @x '*' 'one' = x@
-- [/multiplicative associativity/]
--     @x '*' (y '*' z) = (x '*' y) '*' z@
-- [/left-distributivity of '*' over '+'/]
--     @x '*' (y '+' z) = (x '*' y) '+' (x '*' z)@
-- [/right-distributivity of '*' over '+'/]
--     @(x '+' y) '*' z = (x '*' z) '+' (y '*' z)@
-- [/annihilation/]
--     @'zero' '*' x = x '*' 'zero' = 'zero'@

class Semiring a where
  {-# MINIMAL plus, times, (zero, one | fromNatural) #-}
  plus  :: a -> a -> a -- ^ Commutative Operation
  zero  :: a           -- ^ Commutative Unit
  zero = Natural -> a
forall a. Semiring a => Natural -> a
fromNatural Natural
0
  times :: a -> a -> a -- ^ Associative Operation
  one   :: a           -- ^ Associative Unit
  one = Natural -> a
forall a. Semiring a => Natural -> a
fromNatural Natural
1
  fromNatural :: Natural -> a -- ^ Homomorphism of additive semigroups
  fromNatural Natural
0 = a
forall a. Semiring a => a
zero
  fromNatural Natural
n = Add' a -> a
forall a. Add' a -> a
getAdd' (Natural -> Add' a -> Add' a
forall b. Integral b => b -> Add' a -> Add' a
forall a b. (Semigroup a, Integral b) => b -> a -> a
stimes Natural
n (a -> Add' a
forall a. a -> Add' a
Add' a
forall a. Semiring a => a
one))

-- | The class of semirings with an additive inverse.
--
--     @'negate' a '+' a = 'zero'@

class Semiring a => Ring a where
  {-# MINIMAL negate #-}
  negate :: a -> a

-- | Subtract two 'Ring' values. For any type @R@ with
-- a 'Num.Num' instance, this is the same as '(Prelude.-)'.
--
--     @x `minus` y = x '+' 'negate' y@
minus :: Ring a => a -> a -> a
minus :: forall a. Ring a => a -> a -> a
minus a
x a
y = a
x a -> a -> a
forall a. Semiring a => a -> a -> a
+ a -> a
forall a. Ring a => a -> a
negate a
y
{-# INLINE minus #-}

-- | Convert from integer to ring.
--
-- When @{-#@ @LANGUAGE RebindableSyntax #-}@ is enabled,
-- this function is used for desugaring integer literals.
-- This may be used to facilitate transition from 'Num.Num' to 'Ring':
-- no need to replace 0 and 1 with 'one' and 'zero'
-- or to cast numeric literals.
fromInteger :: Ring a => Integer -> a
fromInteger :: forall a. Ring a => Integer -> a
fromInteger Integer
x
  | Integer
x Integer -> Integer -> Bool
forall a. Ord a => a -> a -> Bool
>= Integer
0    = Natural -> a
forall a. Semiring a => Natural -> a
fromNatural (Integer -> Natural
forall a. Num a => Integer -> a
Num.fromInteger Integer
x)
  | Bool
otherwise = a -> a
forall a. Ring a => a -> a
negate (Natural -> a
forall a. Semiring a => Natural -> a
fromNatural (Integer -> Natural
forall a. Num a => Integer -> a
Num.fromInteger (Integer -> Integer
forall a. Num a => a -> a
Num.negate Integer
x)))
{-# INLINE fromInteger #-}

-- | Convert from integral to ring.
fromIntegral :: (Integral a, Ring b) => a -> b
fromIntegral :: forall a b. (Integral a, Ring b) => a -> b
fromIntegral a
x
  | a
x a -> a -> Bool
forall a. Ord a => a -> a -> Bool
>= a
0    = Natural -> b
forall a. Semiring a => Natural -> a
fromNatural (a -> Natural
forall a b. (Integral a, Num b) => a -> b
Real.fromIntegral a
x)
  | Bool
otherwise = b -> b
forall a. Ring a => a -> a
negate (Natural -> b
forall a. Semiring a => Natural -> a
fromNatural (a -> Natural
forall a b. (Integral a, Num b) => a -> b
Real.fromIntegral (a -> a
forall a. Num a => a -> a
Num.negate a
x)))
{-# INLINE fromIntegral #-}

{--------------------------------------------------------------------
  Instances (base)
--------------------------------------------------------------------}

instance (Semiring a, Semiring b) => Semiring (a,b) where
  zero :: (a, b)
zero = (a
forall a. Semiring a => a
zero, b
forall a. Semiring a => a
zero)
  one :: (a, b)
one = (a
forall a. Semiring a => a
one, b
forall a. Semiring a => a
one)
  plus :: (a, b) -> (a, b) -> (a, b)
plus (a
x1, b
x2) (a
y1, b
y2) =
    (a
x1 a -> a -> a
forall a. Semiring a => a -> a -> a
`plus` a
y1, b
x2 b -> b -> b
forall a. Semiring a => a -> a -> a
`plus` b
y2)
  times :: (a, b) -> (a, b) -> (a, b)
times (a
x1, b
x2) (a
y1, b
y2) =
    (a
x1 a -> a -> a
forall a. Semiring a => a -> a -> a
`times` a
y1, b
x2 b -> b -> b
forall a. Semiring a => a -> a -> a
`times` b
y2)

instance (Semiring a, Semiring b, Semiring c) => Semiring (a,b,c) where
  zero :: (a, b, c)
zero = (a
forall a. Semiring a => a
zero, b
forall a. Semiring a => a
zero, c
forall a. Semiring a => a
zero)
  one :: (a, b, c)
one = (a
forall a. Semiring a => a
one, b
forall a. Semiring a => a
one, c
forall a. Semiring a => a
one)
  plus :: (a, b, c) -> (a, b, c) -> (a, b, c)
plus (a
x1, b
x2, c
x3) (a
y1, b
y2, c
y3) =
    (a
x1 a -> a -> a
forall a. Semiring a => a -> a -> a
`plus` a
y1, b
x2 b -> b -> b
forall a. Semiring a => a -> a -> a
`plus` b
y2, c
x3 c -> c -> c
forall a. Semiring a => a -> a -> a
`plus` c
y3)
  times :: (a, b, c) -> (a, b, c) -> (a, b, c)
times (a
x1, b
x2, c
x3) (a
y1, b
y2, c
y3) =
    (a
x1 a -> a -> a
forall a. Semiring a => a -> a -> a
`times` a
y1, b
x2 b -> b -> b
forall a. Semiring a => a -> a -> a
`times` b
y2, c
x3 c -> c -> c
forall a. Semiring a => a -> a -> a
`times` c
y3)

instance (Semiring a, Semiring b, Semiring c, Semiring d) => Semiring (a,b,c,d) where
  zero :: (a, b, c, d)
zero = (a
forall a. Semiring a => a
zero, b
forall a. Semiring a => a
zero, c
forall a. Semiring a => a
zero, d
forall a. Semiring a => a
zero)
  one :: (a, b, c, d)
one = (a
forall a. Semiring a => a
one, b
forall a. Semiring a => a
one, c
forall a. Semiring a => a
one, d
forall a. Semiring a => a
one)
  plus :: (a, b, c, d) -> (a, b, c, d) -> (a, b, c, d)
plus (a
x1, b
x2, c
x3, d
x4) (a
y1, b
y2, c
y3, d
y4) =
    (a
x1 a -> a -> a
forall a. Semiring a => a -> a -> a
`plus` a
y1, b
x2 b -> b -> b
forall a. Semiring a => a -> a -> a
`plus` b
y2, c
x3 c -> c -> c
forall a. Semiring a => a -> a -> a
`plus` c
y3, d
x4 d -> d -> d
forall a. Semiring a => a -> a -> a
`plus` d
y4)
  times :: (a, b, c, d) -> (a, b, c, d) -> (a, b, c, d)
times (a
x1, b
x2, c
x3, d
x4) (a
y1, b
y2, c
y3, d
y4) =
    (a
x1 a -> a -> a
forall a. Semiring a => a -> a -> a
`times` a
y1, b
x2 b -> b -> b
forall a. Semiring a => a -> a -> a
`times` b
y2, c
x3 c -> c -> c
forall a. Semiring a => a -> a -> a
`times` c
y3, d
x4 d -> d -> d
forall a. Semiring a => a -> a -> a
`times` d
y4)

instance (Semiring a, Semiring b, Semiring c, Semiring d, Semiring e) => Semiring (a,b,c,d,e) where
  zero :: (a, b, c, d, e)
zero = (a
forall a. Semiring a => a
zero, b
forall a. Semiring a => a
zero, c
forall a. Semiring a => a
zero, d
forall a. Semiring a => a
zero, e
forall a. Semiring a => a
zero)
  one :: (a, b, c, d, e)
one = (a
forall a. Semiring a => a
one, b
forall a. Semiring a => a
one, c
forall a. Semiring a => a
one, d
forall a. Semiring a => a
one, e
forall a. Semiring a => a
one)
  plus :: (a, b, c, d, e) -> (a, b, c, d, e) -> (a, b, c, d, e)
plus (a
x1, b
x2, c
x3, d
x4, e
x5) (a
y1, b
y2, c
y3, d
y4, e
y5) =
    (a
x1 a -> a -> a
forall a. Semiring a => a -> a -> a
`plus` a
y1, b
x2 b -> b -> b
forall a. Semiring a => a -> a -> a
`plus` b
y2, c
x3 c -> c -> c
forall a. Semiring a => a -> a -> a
`plus` c
y3, d
x4 d -> d -> d
forall a. Semiring a => a -> a -> a
`plus` d
y4, e
x5 e -> e -> e
forall a. Semiring a => a -> a -> a
`plus` e
y5)
  times :: (a, b, c, d, e) -> (a, b, c, d, e) -> (a, b, c, d, e)
times (a
x1, b
x2, c
x3, d
x4, e
x5) (a
y1, b
y2, c
y3, d
y4, e
y5) =
    (a
x1 a -> a -> a
forall a. Semiring a => a -> a -> a
`times` a
y1, b
x2 b -> b -> b
forall a. Semiring a => a -> a -> a
`times` b
y2, c
x3 c -> c -> c
forall a. Semiring a => a -> a -> a
`times` c
y3, d
x4 d -> d -> d
forall a. Semiring a => a -> a -> a
`times` d
y4, e
x5 e -> e -> e
forall a. Semiring a => a -> a -> a
`times` e
y5)

instance (Semiring a, Semiring b, Semiring c, Semiring d, Semiring e, Semiring f) => Semiring (a,b,c,d,e,f) where
  zero :: (a, b, c, d, e, f)
zero = (a
forall a. Semiring a => a
zero, b
forall a. Semiring a => a
zero, c
forall a. Semiring a => a
zero, d
forall a. Semiring a => a
zero, e
forall a. Semiring a => a
zero, f
forall a. Semiring a => a
zero)
  one :: (a, b, c, d, e, f)
one = (a
forall a. Semiring a => a
one, b
forall a. Semiring a => a
one, c
forall a. Semiring a => a
one, d
forall a. Semiring a => a
one, e
forall a. Semiring a => a
one, f
forall a. Semiring a => a
one)
  plus :: (a, b, c, d, e, f) -> (a, b, c, d, e, f) -> (a, b, c, d, e, f)
plus (a
x1, b
x2, c
x3, d
x4, e
x5, f
x6) (a
y1, b
y2, c
y3, d
y4, e
y5, f
y6) =
    (a
x1 a -> a -> a
forall a. Semiring a => a -> a -> a
`plus` a
y1, b
x2 b -> b -> b
forall a. Semiring a => a -> a -> a
`plus` b
y2, c
x3 c -> c -> c
forall a. Semiring a => a -> a -> a
`plus` c
y3, d
x4 d -> d -> d
forall a. Semiring a => a -> a -> a
`plus` d
y4, e
x5 e -> e -> e
forall a. Semiring a => a -> a -> a
`plus` e
y5, f
x6 f -> f -> f
forall a. Semiring a => a -> a -> a
`plus` f
y6)
  times :: (a, b, c, d, e, f) -> (a, b, c, d, e, f) -> (a, b, c, d, e, f)
times (a
x1, b
x2, c
x3, d
x4, e
x5, f
x6) (a
y1, b
y2, c
y3, d
y4, e
y5, f
y6) =
    (a
x1 a -> a -> a
forall a. Semiring a => a -> a -> a
`times` a
y1, b
x2 b -> b -> b
forall a. Semiring a => a -> a -> a
`times` b
y2, c
x3 c -> c -> c
forall a. Semiring a => a -> a -> a
`times` c
y3, d
x4 d -> d -> d
forall a. Semiring a => a -> a -> a
`times` d
y4, e
x5 e -> e -> e
forall a. Semiring a => a -> a -> a
`times` e
y5, f
x6 f -> f -> f
forall a. Semiring a => a -> a -> a
`times` f
y6)

instance (Semiring a, Semiring b, Semiring c, Semiring d, Semiring e, Semiring f, Semiring g) => Semiring (a,b,c,d,e,f,g) where
  zero :: (a, b, c, d, e, f, g)
zero = (a
forall a. Semiring a => a
zero, b
forall a. Semiring a => a
zero, c
forall a. Semiring a => a
zero, d
forall a. Semiring a => a
zero, e
forall a. Semiring a => a
zero, f
forall a. Semiring a => a
zero, g
forall a. Semiring a => a
zero)
  one :: (a, b, c, d, e, f, g)
one = (a
forall a. Semiring a => a
one, b
forall a. Semiring a => a
one, c
forall a. Semiring a => a
one, d
forall a. Semiring a => a
one, e
forall a. Semiring a => a
one, f
forall a. Semiring a => a
one, g
forall a. Semiring a => a
one)
  plus :: (a, b, c, d, e, f, g)
-> (a, b, c, d, e, f, g) -> (a, b, c, d, e, f, g)
plus (a
x1, b
x2, c
x3, d
x4, e
x5, f
x6, g
x7) (a
y1, b
y2, c
y3, d
y4, e
y5, f
y6, g
y7) =
    (a
x1 a -> a -> a
forall a. Semiring a => a -> a -> a
`plus` a
y1, b
x2 b -> b -> b
forall a. Semiring a => a -> a -> a
`plus` b
y2, c
x3 c -> c -> c
forall a. Semiring a => a -> a -> a
`plus` c
y3, d
x4 d -> d -> d
forall a. Semiring a => a -> a -> a
`plus` d
y4, e
x5 e -> e -> e
forall a. Semiring a => a -> a -> a
`plus` e
y5, f
x6 f -> f -> f
forall a. Semiring a => a -> a -> a
`plus` f
y6, g
x7 g -> g -> g
forall a. Semiring a => a -> a -> a
`plus` g
y7)
  times :: (a, b, c, d, e, f, g)
-> (a, b, c, d, e, f, g) -> (a, b, c, d, e, f, g)
times (a
x1, b
x2, c
x3, d
x4, e
x5, f
x6, g
x7) (a
y1, b
y2, c
y3, d
y4, e
y5, f
y6, g
y7) =
    (a
x1 a -> a -> a
forall a. Semiring a => a -> a -> a
`times` a
y1, b
x2 b -> b -> b
forall a. Semiring a => a -> a -> a
`times` b
y2, c
x3 c -> c -> c
forall a. Semiring a => a -> a -> a
`times` c
y3, d
x4 d -> d -> d
forall a. Semiring a => a -> a -> a
`times` d
y4, e
x5 e -> e -> e
forall a. Semiring a => a -> a -> a
`times` e
y5, f
x6 f -> f -> f
forall a. Semiring a => a -> a -> a
`times` f
y6, g
x7 g -> g -> g
forall a. Semiring a => a -> a -> a
`times` g
y7)

instance (Ring a, Ring b) => Ring (a,b) where
  negate :: (a, b) -> (a, b)
negate (a
x1, b
x2) = (a -> a
forall a. Ring a => a -> a
negate a
x1, b -> b
forall a. Ring a => a -> a
negate b
x2)

instance (Ring a, Ring b, Ring c) => Ring (a,b,c) where
  negate :: (a, b, c) -> (a, b, c)
negate (a
x1, b
x2, c
x3) = (a -> a
forall a. Ring a => a -> a
negate a
x1, b -> b
forall a. Ring a => a -> a
negate b
x2, c -> c
forall a. Ring a => a -> a
negate c
x3)

instance (Ring a, Ring b, Ring c, Ring d) => Ring (a,b,c,d) where
  negate :: (a, b, c, d) -> (a, b, c, d)
negate (a
x1, b
x2, c
x3, d
x4) = (a -> a
forall a. Ring a => a -> a
negate a
x1, b -> b
forall a. Ring a => a -> a
negate b
x2, c -> c
forall a. Ring a => a -> a
negate c
x3, d -> d
forall a. Ring a => a -> a
negate d
x4)

instance (Ring a, Ring b, Ring c, Ring d, Ring e) => Ring (a,b,c,d,e) where
  negate :: (a, b, c, d, e) -> (a, b, c, d, e)
negate (a
x1, b
x2, c
x3, d
x4, e
x5) = (a -> a
forall a. Ring a => a -> a
negate a
x1, b -> b
forall a. Ring a => a -> a
negate b
x2, c -> c
forall a. Ring a => a -> a
negate c
x3, d -> d
forall a. Ring a => a -> a
negate d
x4, e -> e
forall a. Ring a => a -> a
negate e
x5)

instance (Ring a, Ring b, Ring c, Ring d, Ring e, Ring f) => Ring (a,b,c,d,e,f) where
  negate :: (a, b, c, d, e, f) -> (a, b, c, d, e, f)
negate (a
x1, b
x2, c
x3, d
x4, e
x5, f
x6) = (a -> a
forall a. Ring a => a -> a
negate a
x1, b -> b
forall a. Ring a => a -> a
negate b
x2, c -> c
forall a. Ring a => a -> a
negate c
x3, d -> d
forall a. Ring a => a -> a
negate d
x4, e -> e
forall a. Ring a => a -> a
negate e
x5, f -> f
forall a. Ring a => a -> a
negate f
x6)

instance (Ring a, Ring b, Ring c, Ring d, Ring e, Ring f, Ring g) => Ring (a,b,c,d,e,f,g) where
  negate :: (a, b, c, d, e, f, g) -> (a, b, c, d, e, f, g)
negate (a
x1, b
x2, c
x3, d
x4, e
x5, f
x6, g
x7) = (a -> a
forall a. Ring a => a -> a
negate a
x1, b -> b
forall a. Ring a => a -> a
negate b
x2, c -> c
forall a. Ring a => a -> a
negate c
x3, d -> d
forall a. Ring a => a -> a
negate d
x4, e -> e
forall a. Ring a => a -> a
negate e
x5, f -> f
forall a. Ring a => a -> a
negate f
x6, g -> g
forall a. Ring a => a -> a
negate g
x7)

instance Semiring b => Semiring (a -> b) where
  plus :: (a -> b) -> (a -> b) -> a -> b
plus a -> b
f a -> b
g    = \a
x -> a -> b
f a
x b -> b -> b
forall a. Semiring a => a -> a -> a
`plus` a -> b
g a
x
  zero :: a -> b
zero        = b -> a -> b
forall a b. a -> b -> a
const b
forall a. Semiring a => a
zero
  times :: (a -> b) -> (a -> b) -> a -> b
times a -> b
f a -> b
g   = \a
x -> a -> b
f a
x b -> b -> b
forall a. Semiring a => a -> a -> a
`times` a -> b
g a
x
  one :: a -> b
one         = b -> a -> b
forall a b. a -> b -> a
const b
forall a. Semiring a => a
one
  fromNatural :: Natural -> a -> b
fromNatural = b -> a -> b
forall a b. a -> b -> a
const (b -> a -> b) -> (Natural -> b) -> Natural -> a -> b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Natural -> b
forall a. Semiring a => Natural -> a
fromNatural
  {-# INLINE plus  #-}
  {-# INLINE zero  #-}
  {-# INLINE times #-}
  {-# INLINE one   #-}
  {-# INLINE fromNatural #-}

instance Ring b => Ring (a -> b) where
  negate :: (a -> b) -> a -> b
negate a -> b
f a
x = b -> b
forall a. Ring a => a -> a
negate (a -> b
f a
x)
  {-# INLINE negate #-}

instance Semiring () where
  plus :: () -> () -> ()
plus ()
_ ()
_  = ()
  zero :: ()
zero      = ()
  times :: () -> () -> ()
times ()
_ ()
_ = ()
  one :: ()
one       = ()
  fromNatural :: Natural -> ()
fromNatural Natural
_ = ()
  {-# INLINE plus  #-}
  {-# INLINE zero  #-}
  {-# INLINE times #-}
  {-# INLINE one   #-}
  {-# INLINE fromNatural #-}

instance Ring () where
  negate :: () -> ()
negate ()
_ = ()
  {-# INLINE negate #-}

instance Semiring (Proxy a) where
  plus :: Proxy a -> Proxy a -> Proxy a
plus Proxy a
_ Proxy a
_  = Proxy a
forall {k} (t :: k). Proxy t
Proxy
  zero :: Proxy a
zero      = Proxy a
forall {k} (t :: k). Proxy t
Proxy
  times :: Proxy a -> Proxy a -> Proxy a
times Proxy a
_ Proxy a
_ = Proxy a
forall {k} (t :: k). Proxy t
Proxy
  one :: Proxy a
one       = Proxy a
forall {k} (t :: k). Proxy t
Proxy
  fromNatural :: Natural -> Proxy a
fromNatural Natural
_ = Proxy a
forall {k} (t :: k). Proxy t
Proxy
  {-# INLINE plus  #-}
  {-# INLINE zero  #-}
  {-# INLINE times #-}
  {-# INLINE one   #-}
  {-# INLINE fromNatural #-}

instance Semiring Bool where
  plus :: Bool -> Bool -> Bool
plus  = Bool -> Bool -> Bool
(||)
  zero :: Bool
zero  = Bool
False
  times :: Bool -> Bool -> Bool
times = Bool -> Bool -> Bool
(&&)
  one :: Bool
one   = Bool
True
  fromNatural :: Natural -> Bool
fromNatural Natural
0 = Bool
False
  fromNatural Natural
_ = Bool
True
  {-# INLINE plus  #-}
  {-# INLINE zero  #-}
  {-# INLINE times #-}
  {-# INLINE one   #-}
  {-# INLINE fromNatural #-}

instance Semiring a => Semiring (Maybe a) where
  zero :: Maybe a
zero  = Maybe a
forall a. Maybe a
Nothing
  one :: Maybe a
one   = a -> Maybe a
forall a. a -> Maybe a
Just a
forall a. Semiring a => a
one

  plus :: Maybe a -> Maybe a -> Maybe a
plus Maybe a
Nothing Maybe a
y = Maybe a
y
  plus Maybe a
x Maybe a
Nothing = Maybe a
x
  plus (Just a
x) (Just a
y) = a -> Maybe a
forall a. a -> Maybe a
Just (a -> a -> a
forall a. Semiring a => a -> a -> a
plus a
x a
y)

  times :: Maybe a -> Maybe a -> Maybe a
times Maybe a
Nothing Maybe a
_ = Maybe a
forall a. Maybe a
Nothing
  times Maybe a
_ Maybe a
Nothing = Maybe a
forall a. Maybe a
Nothing
  times (Just a
x) (Just a
y) = a -> Maybe a
forall a. a -> Maybe a
Just (a -> a -> a
forall a. Semiring a => a -> a -> a
times a
x a
y)

  fromNatural :: Natural -> Maybe a
fromNatural Natural
0 = Maybe a
forall a. Maybe a
Nothing
  fromNatural Natural
n = a -> Maybe a
forall a. a -> Maybe a
Just (Natural -> a
forall a. Semiring a => Natural -> a
fromNatural Natural
n)
  {-# INLINE plus  #-}
  {-# INLINE zero  #-}
  {-# INLINE times #-}
  {-# INLINE one   #-}
  {-# INLINE fromNatural #-}

instance Semiring a => Semiring (IO a) where
  zero :: IO a
zero  = a -> IO a
forall a. a -> IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure a
forall a. Semiring a => a
zero
  one :: IO a
one   = a -> IO a
forall a. a -> IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure a
forall a. Semiring a => a
one
  plus :: IO a -> IO a -> IO a
plus  = (a -> a -> a) -> IO a -> IO a -> IO a
forall a b c. (a -> b -> c) -> IO a -> IO b -> IO c
forall (f :: * -> *) a b c.
Applicative f =>
(a -> b -> c) -> f a -> f b -> f c
liftA2 a -> a -> a
forall a. Semiring a => a -> a -> a
plus
  times :: IO a -> IO a -> IO a
times = (a -> a -> a) -> IO a -> IO a -> IO a
forall a b c. (a -> b -> c) -> IO a -> IO b -> IO c
forall (f :: * -> *) a b c.
Applicative f =>
(a -> b -> c) -> f a -> f b -> f c
liftA2 a -> a -> a
forall a. Semiring a => a -> a -> a
times
  fromNatural :: Natural -> IO a
fromNatural = a -> IO a
forall a. a -> IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (a -> IO a) -> (Natural -> a) -> Natural -> IO a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Natural -> a
forall a. Semiring a => Natural -> a
fromNatural
  {-# INLINE plus  #-}
  {-# INLINE zero  #-}
  {-# INLINE times #-}
  {-# INLINE one   #-}
  {-# INLINE fromNatural #-}

instance Ring a => Ring (IO a) where
  negate :: IO a -> IO a
negate = (a -> a) -> IO a -> IO a
forall a b. (a -> b) -> IO a -> IO b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap a -> a
forall a. Ring a => a -> a
negate
  {-# INLINE negate #-}

instance Semiring a => Semiring (Dual a) where
  zero :: Dual a
zero = a -> Dual a
forall a. a -> Dual a
Dual a
forall a. Semiring a => a
zero
  Dual a
x plus :: Dual a -> Dual a -> Dual a
`plus` Dual a
y = a -> Dual a
forall a. a -> Dual a
Dual (a
y a -> a -> a
forall a. Semiring a => a -> a -> a
`plus` a
x)
  one :: Dual a
one = a -> Dual a
forall a. a -> Dual a
Dual a
forall a. Semiring a => a
one
  Dual a
x times :: Dual a -> Dual a -> Dual a
`times` Dual a
y = a -> Dual a
forall a. a -> Dual a
Dual (a
y a -> a -> a
forall a. Semiring a => a -> a -> a
`times` a
x)
  fromNatural :: Natural -> Dual a
fromNatural = a -> Dual a
forall a. a -> Dual a
Dual (a -> Dual a) -> (Natural -> a) -> Natural -> Dual a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Natural -> a
forall a. Semiring a => Natural -> a
fromNatural
  {-# INLINE plus  #-}
  {-# INLINE zero  #-}
  {-# INLINE times #-}
  {-# INLINE one   #-}
  {-# INLINE fromNatural #-}

instance Ring a => Ring (Dual a) where
  negate :: Dual a -> Dual a
negate (Dual a
x) = a -> Dual a
forall a. a -> Dual a
Dual (a -> a
forall a. Ring a => a -> a
negate a
x)
  {-# INLINE negate #-}

instance Semiring a => Semiring (Const a b) where
  zero :: Const a b
zero = a -> Const a b
forall {k} a (b :: k). a -> Const a b
Const a
forall a. Semiring a => a
zero
  one :: Const a b
one  = a -> Const a b
forall {k} a (b :: k). a -> Const a b
Const a
forall a. Semiring a => a
one
  plus :: Const a b -> Const a b -> Const a b
plus  (Const a
x) (Const a
y) = a -> Const a b
forall {k} a (b :: k). a -> Const a b
Const (a
x a -> a -> a
forall a. Semiring a => a -> a -> a
`plus`  a
y)
  times :: Const a b -> Const a b -> Const a b
times (Const a
x) (Const a
y) = a -> Const a b
forall {k} a (b :: k). a -> Const a b
Const (a
x a -> a -> a
forall a. Semiring a => a -> a -> a
`times` a
y)
  fromNatural :: Natural -> Const a b
fromNatural = a -> Const a b
forall {k} a (b :: k). a -> Const a b
Const (a -> Const a b) -> (Natural -> a) -> Natural -> Const a b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Natural -> a
forall a. Semiring a => Natural -> a
fromNatural
  {-# INLINE plus  #-}
  {-# INLINE zero  #-}
  {-# INLINE times #-}
  {-# INLINE one   #-}
  {-# INLINE fromNatural #-}

instance Ring a => Ring (Const a b) where
  negate :: Const a b -> Const a b
negate (Const a
x) = a -> Const a b
forall {k} a (b :: k). a -> Const a b
Const (a -> a
forall a. Ring a => a -> a
negate a
x)
  {-# INLINE negate #-}

-- | This instance can suffer due to floating point arithmetic.
instance Ring a => Semiring (Complex a) where
  zero :: Complex a
zero = a
forall a. Semiring a => a
zero a -> a -> Complex a
forall a. a -> a -> Complex a
:+ a
forall a. Semiring a => a
zero
  one :: Complex a
one  = a
forall a. Semiring a => a
one  a -> a -> Complex a
forall a. a -> a -> Complex a
:+ a
forall a. Semiring a => a
zero
  plus :: Complex a -> Complex a -> Complex a
plus  (a
x :+ a
y) (a
x' :+ a
y') = a -> a -> a
forall a. Semiring a => a -> a -> a
plus a
x a
x' a -> a -> Complex a
forall a. a -> a -> Complex a
:+ a -> a -> a
forall a. Semiring a => a -> a -> a
plus a
y a
y'
  times :: Complex a -> Complex a -> Complex a
times (a
x :+ a
y) (a
x' :+ a
y')
    = (a
x a -> a -> a
forall a. Semiring a => a -> a -> a
* a
x' a -> a -> a
forall a. Ring a => a -> a -> a
- (a
y a -> a -> a
forall a. Semiring a => a -> a -> a
* a
y')) a -> a -> Complex a
forall a. a -> a -> Complex a
:+ (a
x a -> a -> a
forall a. Semiring a => a -> a -> a
* a
y' a -> a -> a
forall a. Semiring a => a -> a -> a
+ a
y a -> a -> a
forall a. Semiring a => a -> a -> a
* a
x')
  fromNatural :: Natural -> Complex a
fromNatural Natural
n = Natural -> a
forall a. Semiring a => Natural -> a
fromNatural Natural
n a -> a -> Complex a
forall a. a -> a -> Complex a
:+ a
forall a. Semiring a => a
zero
  {-# INLINE plus  #-}
  {-# INLINE zero  #-}
  {-# INLINE times #-}
  {-# INLINE one   #-}
  {-# INLINE fromNatural #-}

instance Ring a => Ring (Complex a) where
  negate :: Complex a -> Complex a
negate (a
x :+ a
y) = a -> a
forall a. Ring a => a -> a
negate a
x a -> a -> Complex a
forall a. a -> a -> Complex a
:+ a -> a
forall a. Ring a => a -> a
negate a
y
  {-# INLINE negate #-}

#if MIN_VERSION_base(4,12,0)
instance (Semiring a, Applicative f) => Semiring (Ap f a) where
  zero :: Ap f a
zero  = a -> Ap f a
forall a. a -> Ap f a
forall (f :: * -> *) a. Applicative f => a -> f a
pure a
forall a. Semiring a => a
zero
  one :: Ap f a
one   = a -> Ap f a
forall a. a -> Ap f a
forall (f :: * -> *) a. Applicative f => a -> f a
pure a
forall a. Semiring a => a
one
  plus :: Ap f a -> Ap f a -> Ap f a
plus  = (a -> a -> a) -> Ap f a -> Ap f a -> Ap f a
forall a b c. (a -> b -> c) -> Ap f a -> Ap f b -> Ap f c
forall (f :: * -> *) a b c.
Applicative f =>
(a -> b -> c) -> f a -> f b -> f c
liftA2 a -> a -> a
forall a. Semiring a => a -> a -> a
plus
  times :: Ap f a -> Ap f a -> Ap f a
times = (a -> a -> a) -> Ap f a -> Ap f a -> Ap f a
forall a b c. (a -> b -> c) -> Ap f a -> Ap f b -> Ap f c
forall (f :: * -> *) a b c.
Applicative f =>
(a -> b -> c) -> f a -> f b -> f c
liftA2 a -> a -> a
forall a. Semiring a => a -> a -> a
times
  fromNatural :: Natural -> Ap f a
fromNatural = a -> Ap f a
forall a. a -> Ap f a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (a -> Ap f a) -> (Natural -> a) -> Natural -> Ap f a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Natural -> a
forall a. Semiring a => Natural -> a
fromNatural
  {-# INLINE plus  #-}
  {-# INLINE zero  #-}
  {-# INLINE times #-}
  {-# INLINE one   #-}
  {-# INLINE fromNatural #-}

instance (Ring a, Applicative f) => Ring (Ap f a) where
  negate :: Ap f a -> Ap f a
negate = (a -> a) -> Ap f a -> Ap f a
forall a b. (a -> b) -> Ap f a -> Ap f b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap a -> a
forall a. Ring a => a -> a
negate
  {-# INLINE negate #-}
#endif

#if MIN_VERSION_base(4,12,0)
deriving instance Semiring (Predicate a)

deriving instance Semiring a => Semiring (Equivalence a)

deriving instance Semiring a => Semiring (Op a b)
deriving instance Ring a => Ring (Op a b)
#endif

instance Integral a => Semiring (Ratio a) where
  {-# SPECIALIZE instance Semiring Rational #-}
  zero :: Ratio a
zero  = a
0 a -> a -> Ratio a
forall a. Integral a => a -> a -> Ratio a
% a
1
  one :: Ratio a
one   = a
1 a -> a -> Ratio a
forall a. Integral a => a -> a -> Ratio a
% a
1
  plus :: Ratio a -> Ratio a -> Ratio a
plus  = Ratio a -> Ratio a -> Ratio a
forall a. Num a => a -> a -> a
(Num.+)
  times :: Ratio a -> Ratio a -> Ratio a
times = Ratio a -> Ratio a -> Ratio a
forall a. Num a => a -> a -> a
(Num.*)
  fromNatural :: Natural -> Ratio a
fromNatural Natural
n = Natural -> a
forall a b. (Integral a, Num b) => a -> b
Real.fromIntegral Natural
n a -> a -> Ratio a
forall a. Integral a => a -> a -> Ratio a
% a
1
  {-# INLINE zero  #-}
  {-# INLINE one   #-}
  {-# INLINE plus  #-}
  {-# INLINE times #-}
  {-# INLINE fromNatural #-}
deriving instance Semiring a => Semiring (Identity a)
deriving instance Semiring a => Semiring (Down a)
instance HasResolution a => Semiring (Fixed a) where
  zero :: Fixed a
zero  = Fixed a
0
  one :: Fixed a
one   = Fixed a
1
  plus :: Fixed a -> Fixed a -> Fixed a
plus  = Fixed a -> Fixed a -> Fixed a
forall a. Num a => a -> a -> a
(Num.+)
  times :: Fixed a -> Fixed a -> Fixed a
times = Fixed a -> Fixed a -> Fixed a
forall a. Num a => a -> a -> a
(Num.*)
  fromNatural :: Natural -> Fixed a
fromNatural = Natural -> Fixed a
forall a b. (Integral a, Num b) => a -> b
Real.fromIntegral
  {-# INLINE zero  #-}
  {-# INLINE one   #-}
  {-# INLINE plus  #-}
  {-# INLINE times #-}
  {-# INLINE fromNatural #-}

instance Integral a => Ring (Ratio a) where
  negate :: Ratio a -> Ratio a
negate = Ratio a -> Ratio a
forall a. Num a => a -> a
Num.negate
  {-# INLINE negate #-}

deriving instance Ring a => Ring (Down a)
deriving instance Ring a => Ring (Identity a)
instance HasResolution a => Ring (Fixed a) where
  negate :: Fixed a -> Fixed a
negate = Fixed a -> Fixed a
forall a. Num a => a -> a
Num.negate
  {-# INLINE negate #-}

{--------------------------------------------------------------------
  Instances (containers)
--------------------------------------------------------------------}

#if defined(VERSION_containers)

-- | The multiplication laws are satisfied for
--   any underlying 'Monoid', so we require a
--   'Monoid' constraint instead of a 'Semiring'
--   constraint since 'times' can use
--   the context of either.
instance (Ord a, Monoid a) => Semiring (Set a) where
  zero :: Set a
zero  = Set a
forall a. Set a
Set.empty
  one :: Set a
one   = a -> Set a
forall a. a -> Set a
Set.singleton a
forall a. Monoid a => a
mempty
  plus :: Set a -> Set a -> Set a
plus  = Set a -> Set a -> Set a
forall a. Ord a => Set a -> Set a -> Set a
Set.union
  times :: Set a -> Set a -> Set a
times Set a
xs Set a
ys = (a -> Set a) -> Set a -> Set a
forall m a. Monoid m => (a -> m) -> Set a -> m
forall (t :: * -> *) m a.
(Foldable t, Monoid m) =>
(a -> m) -> t a -> m
Foldable.foldMap (((a -> a) -> Set a -> Set a) -> Set a -> (a -> a) -> Set a
forall a b c. (a -> b -> c) -> b -> a -> c
flip (a -> a) -> Set a -> Set a
forall b a. Ord b => (a -> b) -> Set a -> Set b
Set.map Set a
ys ((a -> a) -> Set a) -> (a -> a -> a) -> a -> Set a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> a -> a
forall a. Monoid a => a -> a -> a
mappend) Set a
xs
  fromNatural :: Natural -> Set a
fromNatural Natural
0 = Set a
forall a. Semiring a => a
zero
  fromNatural Natural
_ = Set a
forall a. Semiring a => a
one
  {-# INLINE plus  #-}
  {-# INLINE zero  #-}
  {-# INLINE times #-}
  {-# INLINE one   #-}
  {-# INLINE fromNatural #-}

-- | Wrapper to mimic 'Set' ('Data.Semigroup.Sum' 'Int'),
-- 'Set' ('Data.Semigroup.Product' 'Int'), etc.,
-- while having a more efficient underlying representation.
newtype IntSetOf a = IntSetOf { forall a. IntSetOf a -> IntSet
getIntSet :: IntSet }
  deriving
    ( IntSetOf a -> IntSetOf a -> Bool
(IntSetOf a -> IntSetOf a -> Bool)
-> (IntSetOf a -> IntSetOf a -> Bool) -> Eq (IntSetOf a)
forall a. IntSetOf a -> IntSetOf a -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: forall a. IntSetOf a -> IntSetOf a -> Bool
== :: IntSetOf a -> IntSetOf a -> Bool
$c/= :: forall a. IntSetOf a -> IntSetOf a -> Bool
/= :: IntSetOf a -> IntSetOf a -> Bool
Eq
    , (forall x. IntSetOf a -> Rep (IntSetOf a) x)
-> (forall x. Rep (IntSetOf a) x -> IntSetOf a)
-> Generic (IntSetOf a)
forall x. Rep (IntSetOf a) x -> IntSetOf a
forall x. IntSetOf a -> Rep (IntSetOf a) x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall a x. Rep (IntSetOf a) x -> IntSetOf a
forall a x. IntSetOf a -> Rep (IntSetOf a) x
$cfrom :: forall a x. IntSetOf a -> Rep (IntSetOf a) x
from :: forall x. IntSetOf a -> Rep (IntSetOf a) x
$cto :: forall a x. Rep (IntSetOf a) x -> IntSetOf a
to :: forall x. Rep (IntSetOf a) x -> IntSetOf a
Generic
    , (forall a. IntSetOf a -> Rep1 IntSetOf a)
-> (forall a. Rep1 IntSetOf a -> IntSetOf a) -> Generic1 IntSetOf
forall a. Rep1 IntSetOf a -> IntSetOf a
forall a. IntSetOf a -> Rep1 IntSetOf a
forall k (f :: k -> *).
(forall (a :: k). f a -> Rep1 f a)
-> (forall (a :: k). Rep1 f a -> f a) -> Generic1 f
$cfrom1 :: forall a. IntSetOf a -> Rep1 IntSetOf a
from1 :: forall a. IntSetOf a -> Rep1 IntSetOf a
$cto1 :: forall a. Rep1 IntSetOf a -> IntSetOf a
to1 :: forall a. Rep1 IntSetOf a -> IntSetOf a
Generic1
    , Eq (IntSetOf a)
Eq (IntSetOf a) =>
(IntSetOf a -> IntSetOf a -> Ordering)
-> (IntSetOf a -> IntSetOf a -> Bool)
-> (IntSetOf a -> IntSetOf a -> Bool)
-> (IntSetOf a -> IntSetOf a -> Bool)
-> (IntSetOf a -> IntSetOf a -> Bool)
-> (IntSetOf a -> IntSetOf a -> IntSetOf a)
-> (IntSetOf a -> IntSetOf a -> IntSetOf a)
-> Ord (IntSetOf a)
IntSetOf a -> IntSetOf a -> Bool
IntSetOf a -> IntSetOf a -> Ordering
IntSetOf a -> IntSetOf a -> IntSetOf a
forall a. Eq (IntSetOf a)
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
forall a. IntSetOf a -> IntSetOf a -> Bool
forall a. IntSetOf a -> IntSetOf a -> Ordering
forall a. IntSetOf a -> IntSetOf a -> IntSetOf a
$ccompare :: forall a. IntSetOf a -> IntSetOf a -> Ordering
compare :: IntSetOf a -> IntSetOf a -> Ordering
$c< :: forall a. IntSetOf a -> IntSetOf a -> Bool
< :: IntSetOf a -> IntSetOf a -> Bool
$c<= :: forall a. IntSetOf a -> IntSetOf a -> Bool
<= :: IntSetOf a -> IntSetOf a -> Bool
$c> :: forall a. IntSetOf a -> IntSetOf a -> Bool
> :: IntSetOf a -> IntSetOf a -> Bool
$c>= :: forall a. IntSetOf a -> IntSetOf a -> Bool
>= :: IntSetOf a -> IntSetOf a -> Bool
$cmax :: forall a. IntSetOf a -> IntSetOf a -> IntSetOf a
max :: IntSetOf a -> IntSetOf a -> IntSetOf a
$cmin :: forall a. IntSetOf a -> IntSetOf a -> IntSetOf a
min :: IntSetOf a -> IntSetOf a -> IntSetOf a
Ord
    , ReadPrec [IntSetOf a]
ReadPrec (IntSetOf a)
Int -> ReadS (IntSetOf a)
ReadS [IntSetOf a]
(Int -> ReadS (IntSetOf a))
-> ReadS [IntSetOf a]
-> ReadPrec (IntSetOf a)
-> ReadPrec [IntSetOf a]
-> Read (IntSetOf a)
forall a. ReadPrec [IntSetOf a]
forall a. ReadPrec (IntSetOf a)
forall a. Int -> ReadS (IntSetOf a)
forall a. ReadS [IntSetOf a]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
$creadsPrec :: forall a. Int -> ReadS (IntSetOf a)
readsPrec :: Int -> ReadS (IntSetOf a)
$creadList :: forall a. ReadS [IntSetOf a]
readList :: ReadS [IntSetOf a]
$creadPrec :: forall a. ReadPrec (IntSetOf a)
readPrec :: ReadPrec (IntSetOf a)
$creadListPrec :: forall a. ReadPrec [IntSetOf a]
readListPrec :: ReadPrec [IntSetOf a]
Read
    , Int -> IntSetOf a -> ShowS
[IntSetOf a] -> ShowS
IntSetOf a -> [Char]
(Int -> IntSetOf a -> ShowS)
-> (IntSetOf a -> [Char])
-> ([IntSetOf a] -> ShowS)
-> Show (IntSetOf a)
forall a. Int -> IntSetOf a -> ShowS
forall a. [IntSetOf a] -> ShowS
forall a. IntSetOf a -> [Char]
forall a.
(Int -> a -> ShowS) -> (a -> [Char]) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: forall a. Int -> IntSetOf a -> ShowS
showsPrec :: Int -> IntSetOf a -> ShowS
$cshow :: forall a. IntSetOf a -> [Char]
show :: IntSetOf a -> [Char]
$cshowList :: forall a. [IntSetOf a] -> ShowS
showList :: [IntSetOf a] -> ShowS
Show
    , Typeable
    , NonEmpty (IntSetOf a) -> IntSetOf a
IntSetOf a -> IntSetOf a -> IntSetOf a
(IntSetOf a -> IntSetOf a -> IntSetOf a)
-> (NonEmpty (IntSetOf a) -> IntSetOf a)
-> (forall b. Integral b => b -> IntSetOf a -> IntSetOf a)
-> Semigroup (IntSetOf a)
forall b. Integral b => b -> IntSetOf a -> IntSetOf a
forall a. NonEmpty (IntSetOf a) -> IntSetOf a
forall a. IntSetOf a -> IntSetOf a -> IntSetOf a
forall a.
(a -> a -> a)
-> (NonEmpty a -> a)
-> (forall b. Integral b => b -> a -> a)
-> Semigroup a
forall a b. Integral b => b -> IntSetOf a -> IntSetOf a
$c<> :: forall a. IntSetOf a -> IntSetOf a -> IntSetOf a
<> :: IntSetOf a -> IntSetOf a -> IntSetOf a
$csconcat :: forall a. NonEmpty (IntSetOf a) -> IntSetOf a
sconcat :: NonEmpty (IntSetOf a) -> IntSetOf a
$cstimes :: forall a b. Integral b => b -> IntSetOf a -> IntSetOf a
stimes :: forall b. Integral b => b -> IntSetOf a -> IntSetOf a
Semigroup
    , Semigroup (IntSetOf a)
IntSetOf a
Semigroup (IntSetOf a) =>
IntSetOf a
-> (IntSetOf a -> IntSetOf a -> IntSetOf a)
-> ([IntSetOf a] -> IntSetOf a)
-> Monoid (IntSetOf a)
[IntSetOf a] -> IntSetOf a
IntSetOf a -> IntSetOf a -> IntSetOf a
forall a. Semigroup (IntSetOf a)
forall a. IntSetOf a
forall a.
Semigroup a =>
a -> (a -> a -> a) -> ([a] -> a) -> Monoid a
forall a. [IntSetOf a] -> IntSetOf a
forall a. IntSetOf a -> IntSetOf a -> IntSetOf a
$cmempty :: forall a. IntSetOf a
mempty :: IntSetOf a
$cmappend :: forall a. IntSetOf a -> IntSetOf a -> IntSetOf a
mappend :: IntSetOf a -> IntSetOf a -> IntSetOf a
$cmconcat :: forall a. [IntSetOf a] -> IntSetOf a
mconcat :: [IntSetOf a] -> IntSetOf a
Monoid
    )

instance (Coercible Int a, Monoid a) => Semiring (IntSetOf a) where
  zero :: IntSetOf a
zero  = IntSet -> IntSetOf a
forall a b. Coercible a b => a -> b
coerce IntSet
IntSet.empty
  one :: IntSetOf a
one   = (Int -> IntSet) -> a -> IntSetOf a
forall a b. Coercible a b => a -> b
coerce Int -> IntSet
IntSet.singleton (a
forall a. Monoid a => a
mempty :: a)
  plus :: IntSetOf a -> IntSetOf a -> IntSetOf a
plus  = (IntSet -> IntSet -> IntSet)
-> IntSetOf a -> IntSetOf a -> IntSetOf a
forall a b. Coercible a b => a -> b
coerce IntSet -> IntSet -> IntSet
IntSet.union
  IntSetOf a
xs times :: IntSetOf a -> IntSetOf a -> IntSetOf a
`times` IntSetOf a
ys
    = ([Int] -> IntSet) -> [a] -> IntSetOf a
forall a b. Coercible a b => a -> b
coerce [Int] -> IntSet
IntSet.fromList
        [ a -> a -> a
forall a. Monoid a => a -> a -> a
mappend a
k a
l
        | a
k :: a <- (IntSet -> [Int]) -> IntSetOf a -> [a]
forall a b. Coercible a b => a -> b
coerce IntSet -> [Int]
IntSet.toList IntSetOf a
xs
        , a
l :: a <- (IntSet -> [Int]) -> IntSetOf a -> [a]
forall a b. Coercible a b => a -> b
coerce IntSet -> [Int]
IntSet.toList IntSetOf a
ys
        ]
  fromNatural :: Natural -> IntSetOf a
fromNatural Natural
0 = IntSetOf a
forall a. Semiring a => a
zero
  fromNatural Natural
_ = IntSetOf a
forall a. Semiring a => a
one
  {-# INLINE plus  #-}
  {-# INLINE zero  #-}
  {-# INLINE times #-}
  {-# INLINE one   #-}
  {-# INLINE fromNatural #-}

-- | The multiplication laws are satisfied for
--   any underlying 'Monoid' as the key type,
--   so we require a 'Monoid' constraint instead of
--   a 'Semiring' constraint since 'times' can use
--   the context of either.
instance (Ord k, Monoid k, Semiring v) => Semiring (Map k v) where
  zero :: Map k v
zero = Map k v
forall k a. Map k a
Map.empty
  one :: Map k v
one  = k -> v -> Map k v
forall k a. k -> a -> Map k a
Map.singleton k
forall a. Monoid a => a
mempty v
forall a. Semiring a => a
one
  plus :: Map k v -> Map k v -> Map k v
plus = (v -> v -> v) -> Map k v -> Map k v -> Map k v
forall k a. Ord k => (a -> a -> a) -> Map k a -> Map k a -> Map k a
Map.unionWith v -> v -> v
forall a. Semiring a => a -> a -> a
(+)
  Map k v
xs times :: Map k v -> Map k v -> Map k v
`times` Map k v
ys
    = (v -> v -> v) -> [(k, v)] -> Map k v
forall k a. Ord k => (a -> a -> a) -> [(k, a)] -> Map k a
Map.fromListWith v -> v -> v
forall a. Semiring a => a -> a -> a
(+)
        [ (k -> k -> k
forall a. Monoid a => a -> a -> a
mappend k
k k
l, v
v v -> v -> v
forall a. Semiring a => a -> a -> a
* v
u)
        | (k
k,v
v) <- Map k v -> [(k, v)]
forall k a. Map k a -> [(k, a)]
Map.toList Map k v
xs
        , (k
l,v
u) <- Map k v -> [(k, v)]
forall k a. Map k a -> [(k, a)]
Map.toList Map k v
ys
        ]
  fromNatural :: Natural -> Map k v
fromNatural Natural
0 = Map k v
forall a. Semiring a => a
zero
  fromNatural Natural
n = k -> v -> Map k v
forall k a. k -> a -> Map k a
Map.singleton k
forall a. Monoid a => a
mempty (Natural -> v
forall a. Semiring a => Natural -> a
fromNatural Natural
n)
  {-# INLINE plus  #-}
  {-# INLINE zero  #-}
  {-# INLINE times #-}
  {-# INLINE one   #-}
  {-# INLINE fromNatural #-}

-- | Wrapper to mimic 'Map' ('Data.Semigroup.Sum' 'Int') v,
-- 'Map' ('Data.Semigroup.Product' 'Int') v, etc.,
-- while having a more efficient underlying representation.
newtype IntMapOf k v = IntMapOf { forall k v. IntMapOf k v -> IntMap v
getIntMap :: IntMap v }
  deriving
    ( IntMapOf k v -> IntMapOf k v -> Bool
(IntMapOf k v -> IntMapOf k v -> Bool)
-> (IntMapOf k v -> IntMapOf k v -> Bool) -> Eq (IntMapOf k v)
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
forall k v. Eq v => IntMapOf k v -> IntMapOf k v -> Bool
$c== :: forall k v. Eq v => IntMapOf k v -> IntMapOf k v -> Bool
== :: IntMapOf k v -> IntMapOf k v -> Bool
$c/= :: forall k v. Eq v => IntMapOf k v -> IntMapOf k v -> Bool
/= :: IntMapOf k v -> IntMapOf k v -> Bool
Eq
    , (forall x. IntMapOf k v -> Rep (IntMapOf k v) x)
-> (forall x. Rep (IntMapOf k v) x -> IntMapOf k v)
-> Generic (IntMapOf k v)
forall x. Rep (IntMapOf k v) x -> IntMapOf k v
forall x. IntMapOf k v -> Rep (IntMapOf k v) x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall k v x. Rep (IntMapOf k v) x -> IntMapOf k v
forall k v x. IntMapOf k v -> Rep (IntMapOf k v) x
$cfrom :: forall k v x. IntMapOf k v -> Rep (IntMapOf k v) x
from :: forall x. IntMapOf k v -> Rep (IntMapOf k v) x
$cto :: forall k v x. Rep (IntMapOf k v) x -> IntMapOf k v
to :: forall x. Rep (IntMapOf k v) x -> IntMapOf k v
Generic
    , (forall a. IntMapOf k a -> Rep1 (IntMapOf k) a)
-> (forall a. Rep1 (IntMapOf k) a -> IntMapOf k a)
-> Generic1 (IntMapOf k)
forall a. Rep1 (IntMapOf k) a -> IntMapOf k a
forall a. IntMapOf k a -> Rep1 (IntMapOf k) a
forall k a. Rep1 (IntMapOf k) a -> IntMapOf k a
forall k a. IntMapOf k a -> Rep1 (IntMapOf k) a
forall k (f :: k -> *).
(forall (a :: k). f a -> Rep1 f a)
-> (forall (a :: k). Rep1 f a -> f a) -> Generic1 f
$cfrom1 :: forall k a. IntMapOf k a -> Rep1 (IntMapOf k) a
from1 :: forall a. IntMapOf k a -> Rep1 (IntMapOf k) a
$cto1 :: forall k a. Rep1 (IntMapOf k) a -> IntMapOf k a
to1 :: forall a. Rep1 (IntMapOf k) a -> IntMapOf k a
Generic1
    , Eq (IntMapOf k v)
Eq (IntMapOf k v) =>
(IntMapOf k v -> IntMapOf k v -> Ordering)
-> (IntMapOf k v -> IntMapOf k v -> Bool)
-> (IntMapOf k v -> IntMapOf k v -> Bool)
-> (IntMapOf k v -> IntMapOf k v -> Bool)
-> (IntMapOf k v -> IntMapOf k v -> Bool)
-> (IntMapOf k v -> IntMapOf k v -> IntMapOf k v)
-> (IntMapOf k v -> IntMapOf k v -> IntMapOf k v)
-> Ord (IntMapOf k v)
IntMapOf k v -> IntMapOf k v -> Bool
IntMapOf k v -> IntMapOf k v -> Ordering
IntMapOf k v -> IntMapOf k v -> IntMapOf k v
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
forall k v. Ord v => Eq (IntMapOf k v)
forall k v. Ord v => IntMapOf k v -> IntMapOf k v -> Bool
forall k v. Ord v => IntMapOf k v -> IntMapOf k v -> Ordering
forall k v. Ord v => IntMapOf k v -> IntMapOf k v -> IntMapOf k v
$ccompare :: forall k v. Ord v => IntMapOf k v -> IntMapOf k v -> Ordering
compare :: IntMapOf k v -> IntMapOf k v -> Ordering
$c< :: forall k v. Ord v => IntMapOf k v -> IntMapOf k v -> Bool
< :: IntMapOf k v -> IntMapOf k v -> Bool
$c<= :: forall k v. Ord v => IntMapOf k v -> IntMapOf k v -> Bool
<= :: IntMapOf k v -> IntMapOf k v -> Bool
$c> :: forall k v. Ord v => IntMapOf k v -> IntMapOf k v -> Bool
> :: IntMapOf k v -> IntMapOf k v -> Bool
$c>= :: forall k v. Ord v => IntMapOf k v -> IntMapOf k v -> Bool
>= :: IntMapOf k v -> IntMapOf k v -> Bool
$cmax :: forall k v. Ord v => IntMapOf k v -> IntMapOf k v -> IntMapOf k v
max :: IntMapOf k v -> IntMapOf k v -> IntMapOf k v
$cmin :: forall k v. Ord v => IntMapOf k v -> IntMapOf k v -> IntMapOf k v
min :: IntMapOf k v -> IntMapOf k v -> IntMapOf k v
Ord
    , ReadPrec [IntMapOf k v]
ReadPrec (IntMapOf k v)
Int -> ReadS (IntMapOf k v)
ReadS [IntMapOf k v]
(Int -> ReadS (IntMapOf k v))
-> ReadS [IntMapOf k v]
-> ReadPrec (IntMapOf k v)
-> ReadPrec [IntMapOf k v]
-> Read (IntMapOf k v)
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
forall k v. Read v => ReadPrec [IntMapOf k v]
forall k v. Read v => ReadPrec (IntMapOf k v)
forall k v. Read v => Int -> ReadS (IntMapOf k v)
forall k v. Read v => ReadS [IntMapOf k v]
$creadsPrec :: forall k v. Read v => Int -> ReadS (IntMapOf k v)
readsPrec :: Int -> ReadS (IntMapOf k v)
$creadList :: forall k v. Read v => ReadS [IntMapOf k v]
readList :: ReadS [IntMapOf k v]
$creadPrec :: forall k v. Read v => ReadPrec (IntMapOf k v)
readPrec :: ReadPrec (IntMapOf k v)
$creadListPrec :: forall k v. Read v => ReadPrec [IntMapOf k v]
readListPrec :: ReadPrec [IntMapOf k v]
Read
    , Int -> IntMapOf k v -> ShowS
[IntMapOf k v] -> ShowS
IntMapOf k v -> [Char]
(Int -> IntMapOf k v -> ShowS)
-> (IntMapOf k v -> [Char])
-> ([IntMapOf k v] -> ShowS)
-> Show (IntMapOf k v)
forall a.
(Int -> a -> ShowS) -> (a -> [Char]) -> ([a] -> ShowS) -> Show a
forall k v. Show v => Int -> IntMapOf k v -> ShowS
forall k v. Show v => [IntMapOf k v] -> ShowS
forall k v. Show v => IntMapOf k v -> [Char]
$cshowsPrec :: forall k v. Show v => Int -> IntMapOf k v -> ShowS
showsPrec :: Int -> IntMapOf k v -> ShowS
$cshow :: forall k v. Show v => IntMapOf k v -> [Char]
show :: IntMapOf k v -> [Char]
$cshowList :: forall k v. Show v => [IntMapOf k v] -> ShowS
showList :: [IntMapOf k v] -> ShowS
Show
    , Typeable
    , NonEmpty (IntMapOf k v) -> IntMapOf k v
IntMapOf k v -> IntMapOf k v -> IntMapOf k v
(IntMapOf k v -> IntMapOf k v -> IntMapOf k v)
-> (NonEmpty (IntMapOf k v) -> IntMapOf k v)
-> (forall b. Integral b => b -> IntMapOf k v -> IntMapOf k v)
-> Semigroup (IntMapOf k v)
forall b. Integral b => b -> IntMapOf k v -> IntMapOf k v
forall a.
(a -> a -> a)
-> (NonEmpty a -> a)
-> (forall b. Integral b => b -> a -> a)
-> Semigroup a
forall k v. NonEmpty (IntMapOf k v) -> IntMapOf k v
forall k v. IntMapOf k v -> IntMapOf k v -> IntMapOf k v
forall k v b. Integral b => b -> IntMapOf k v -> IntMapOf k v
$c<> :: forall k v. IntMapOf k v -> IntMapOf k v -> IntMapOf k v
<> :: IntMapOf k v -> IntMapOf k v -> IntMapOf k v
$csconcat :: forall k v. NonEmpty (IntMapOf k v) -> IntMapOf k v
sconcat :: NonEmpty (IntMapOf k v) -> IntMapOf k v
$cstimes :: forall k v b. Integral b => b -> IntMapOf k v -> IntMapOf k v
stimes :: forall b. Integral b => b -> IntMapOf k v -> IntMapOf k v
Semigroup
    , Semigroup (IntMapOf k v)
IntMapOf k v
Semigroup (IntMapOf k v) =>
IntMapOf k v
-> (IntMapOf k v -> IntMapOf k v -> IntMapOf k v)
-> ([IntMapOf k v] -> IntMapOf k v)
-> Monoid (IntMapOf k v)
[IntMapOf k v] -> IntMapOf k v
IntMapOf k v -> IntMapOf k v -> IntMapOf k v
forall a.
Semigroup a =>
a -> (a -> a -> a) -> ([a] -> a) -> Monoid a
forall k v. Semigroup (IntMapOf k v)
forall k v. IntMapOf k v
forall k v. [IntMapOf k v] -> IntMapOf k v
forall k v. IntMapOf k v -> IntMapOf k v -> IntMapOf k v
$cmempty :: forall k v. IntMapOf k v
mempty :: IntMapOf k v
$cmappend :: forall k v. IntMapOf k v -> IntMapOf k v -> IntMapOf k v
mappend :: IntMapOf k v -> IntMapOf k v -> IntMapOf k v
$cmconcat :: forall k v. [IntMapOf k v] -> IntMapOf k v
mconcat :: [IntMapOf k v] -> IntMapOf k v
Monoid
    )

instance (Coercible Int k, Monoid k, Semiring v) => Semiring (IntMapOf k v) where
  zero :: IntMapOf k v
zero = IntMap v -> IntMapOf k v
forall a b. Coercible a b => a -> b
coerce (IntMap v
forall a. IntMap a
IntMap.empty :: IntMap v)
  one :: IntMapOf k v
one  = (Int -> v -> IntMap v) -> k -> v -> IntMapOf k v
forall a b. Coercible a b => a -> b
coerce (Int -> v -> IntMap v
forall a. Int -> a -> IntMap a
IntMap.singleton :: Int -> v -> IntMap v) (k
forall a. Monoid a => a
mempty :: k) (v
forall a. Semiring a => a
one :: v)
  plus :: IntMapOf k v -> IntMapOf k v -> IntMapOf k v
plus = (IntMap v -> IntMap v -> IntMap v)
-> IntMapOf k v -> IntMapOf k v -> IntMapOf k v
forall a b. Coercible a b => a -> b
coerce ((v -> v -> v) -> IntMap v -> IntMap v -> IntMap v
forall a. (a -> a -> a) -> IntMap a -> IntMap a -> IntMap a
IntMap.unionWith v -> v -> v
forall a. Semiring a => a -> a -> a
(+) :: IntMap v -> IntMap v -> IntMap v)
  IntMapOf k v
xs times :: IntMapOf k v -> IntMapOf k v -> IntMapOf k v
`times` IntMapOf k v
ys
    = ([(Int, v)] -> IntMap v) -> [(k, v)] -> IntMapOf k v
forall a b. Coercible a b => a -> b
coerce ((v -> v -> v) -> [(Int, v)] -> IntMap v
forall a. (a -> a -> a) -> [(Int, a)] -> IntMap a
IntMap.fromListWith v -> v -> v
forall a. Semiring a => a -> a -> a
(+) :: [(Int, v)] -> IntMap v)
        [ (k -> k -> k
forall a. Monoid a => a -> a -> a
mappend k
k k
l, v
v v -> v -> v
forall a. Semiring a => a -> a -> a
* v
u)
        | (k
k :: k, v
v :: v) <- (IntMap v -> [(Int, v)]) -> IntMapOf k v -> [(k, v)]
forall a b. Coercible a b => a -> b
coerce (IntMap v -> [(Int, v)]
forall a. IntMap a -> [(Int, a)]
IntMap.toList :: IntMap v -> [(Int, v)]) IntMapOf k v
xs
        , (k
l :: k, v
u :: v) <- (IntMap v -> [(Int, v)]) -> IntMapOf k v -> [(k, v)]
forall a b. Coercible a b => a -> b
coerce (IntMap v -> [(Int, v)]
forall a. IntMap a -> [(Int, a)]
IntMap.toList :: IntMap v -> [(Int, v)]) IntMapOf k v
ys
        ]
  fromNatural :: Natural -> IntMapOf k v
fromNatural Natural
0 = IntMapOf k v
forall a. Semiring a => a
zero
  fromNatural Natural
n = (Int -> v -> IntMap v) -> k -> v -> IntMapOf k v
forall a b. Coercible a b => a -> b
coerce (Int -> v -> IntMap v
forall a. Int -> a -> IntMap a
IntMap.singleton :: Int -> v -> IntMap v) (k
forall a. Monoid a => a
mempty :: k) (Natural -> v
forall a. Semiring a => Natural -> a
fromNatural Natural
n :: v)
  {-# INLINE plus  #-}
  {-# INLINE zero  #-}
  {-# INLINE times #-}
  {-# INLINE one   #-}
  {-# INLINE fromNatural #-}

#endif

{--------------------------------------------------------------------
  Instances (unordered-containers)
--------------------------------------------------------------------}

#if defined(VERSION_unordered_containers)

-- | The multiplication laws are satisfied for
--   any underlying 'Monoid', so we require a
--   'Monoid' constraint instead of a 'Semiring'
--   constraint since 'times' can use
--   the context of either.
instance (Eq a, Hashable a, Monoid a) => Semiring (HashSet a) where
  zero :: HashSet a
zero = HashSet a
forall a. HashSet a
HashSet.empty
  one :: HashSet a
one  = a -> HashSet a
forall a. Hashable a => a -> HashSet a
HashSet.singleton a
forall a. Monoid a => a
mempty
  plus :: HashSet a -> HashSet a -> HashSet a
plus = HashSet a -> HashSet a -> HashSet a
forall a. Eq a => HashSet a -> HashSet a -> HashSet a
HashSet.union
  times :: HashSet a -> HashSet a -> HashSet a
times HashSet a
xs HashSet a
ys = (a -> HashSet a) -> HashSet a -> HashSet a
forall m a. Monoid m => (a -> m) -> HashSet a -> m
forall (t :: * -> *) m a.
(Foldable t, Monoid m) =>
(a -> m) -> t a -> m
Foldable.foldMap (((a -> a) -> HashSet a -> HashSet a)
-> HashSet a -> (a -> a) -> HashSet a
forall a b c. (a -> b -> c) -> b -> a -> c
flip (a -> a) -> HashSet a -> HashSet a
forall b a.
(Hashable b, Eq b) =>
(a -> b) -> HashSet a -> HashSet b
HashSet.map HashSet a
ys ((a -> a) -> HashSet a) -> (a -> a -> a) -> a -> HashSet a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> a -> a
forall a. Monoid a => a -> a -> a
mappend) HashSet a
xs
  fromNatural :: Natural -> HashSet a
fromNatural Natural
0 = HashSet a
forall a. Semiring a => a
zero
  fromNatural Natural
_ = HashSet a
forall a. Semiring a => a
one
  {-# INLINE plus  #-}
  {-# INLINE zero  #-}
  {-# INLINE times #-}
  {-# INLINE one   #-}
  {-# INLINE fromNatural #-}

-- | The multiplication laws are satisfied for
--   any underlying 'Monoid' as the key type,
--   so we require a 'Monoid' constraint instead of
--   a 'Semiring' constraint since 'times' can use
--   the context of either.
instance (Eq k, Hashable k, Monoid k, Semiring v) => Semiring (HashMap k v) where
  zero :: HashMap k v
zero = HashMap k v
forall k v. HashMap k v
HashMap.empty
  one :: HashMap k v
one  = k -> v -> HashMap k v
forall k v. Hashable k => k -> v -> HashMap k v
HashMap.singleton k
forall a. Monoid a => a
mempty v
forall a. Semiring a => a
one
  plus :: HashMap k v -> HashMap k v -> HashMap k v
plus = (v -> v -> v) -> HashMap k v -> HashMap k v -> HashMap k v
forall k v.
Eq k =>
(v -> v -> v) -> HashMap k v -> HashMap k v -> HashMap k v
HashMap.unionWith v -> v -> v
forall a. Semiring a => a -> a -> a
(+)
  HashMap k v
xs times :: HashMap k v -> HashMap k v -> HashMap k v
`times` HashMap k v
ys
    = (v -> v -> v) -> [(k, v)] -> HashMap k v
forall k v.
(Eq k, Hashable k) =>
(v -> v -> v) -> [(k, v)] -> HashMap k v
HashMap.fromListWith v -> v -> v
forall a. Semiring a => a -> a -> a
(+)
        [ (k -> k -> k
forall a. Monoid a => a -> a -> a
mappend k
k k
l, v
v v -> v -> v
forall a. Semiring a => a -> a -> a
* v
u)
        | (k
k,v
v) <- HashMap k v -> [(k, v)]
forall k v. HashMap k v -> [(k, v)]
HashMap.toList HashMap k v
xs
        , (k
l,v
u) <- HashMap k v -> [(k, v)]
forall k v. HashMap k v -> [(k, v)]
HashMap.toList HashMap k v
ys
        ]
  fromNatural :: Natural -> HashMap k v
fromNatural Natural
0 = HashMap k v
forall a. Semiring a => a
zero
  fromNatural Natural
n = k -> v -> HashMap k v
forall k v. Hashable k => k -> v -> HashMap k v
HashMap.singleton k
forall a. Monoid a => a
mempty (Natural -> v
forall a. Semiring a => Natural -> a
fromNatural Natural
n)
  {-# INLINE plus  #-}
  {-# INLINE zero  #-}
  {-# INLINE times #-}
  {-# INLINE one   #-}
  {-# INLINE fromNatural #-}
#endif

-- | Is the value 'zero'?
isZero :: (Eq a, Semiring a) => a -> Bool
isZero :: forall a. (Eq a, Semiring a) => a -> Bool
isZero a
x = a
x a -> a -> Bool
forall a. Eq a => a -> a -> Bool
== a
forall a. Semiring a => a
zero
{-# INLINEABLE isZero #-}

-- | Is the value 'one'?
isOne :: (Eq a, Semiring a) => a -> Bool
isOne :: forall a. (Eq a, Semiring a) => a -> Bool
isOne a
x = a
x a -> a -> Bool
forall a. Eq a => a -> a -> Bool
== a
forall a. Semiring a => a
one
{-# INLINEABLE isOne #-}

#if MIN_VERSION_base(4,12,0)
deriving via (WrappedNum Int) instance Semiring Int
deriving via (WrappedNum Int8) instance Semiring Int8
deriving via (WrappedNum Int16) instance Semiring Int16
deriving via (WrappedNum Int32) instance Semiring Int32
deriving via (WrappedNum Int64) instance Semiring Int64
deriving via (WrappedNum Integer) instance Semiring Integer
deriving via (WrappedNum Word) instance Semiring Word
deriving via (WrappedNum Word8) instance Semiring Word8
deriving via (WrappedNum Word16) instance Semiring Word16
deriving via (WrappedNum Word32) instance Semiring Word32
deriving via (WrappedNum Word64) instance Semiring Word64
deriving via (WrappedNum Float) instance Semiring Float
deriving via (WrappedNum Double) instance Semiring Double
deriving via (WrappedNum CUIntMax) instance Semiring CUIntMax
deriving via (WrappedNum CIntMax) instance Semiring CIntMax
deriving via (WrappedNum CUIntPtr) instance Semiring CUIntPtr
deriving via (WrappedNum CIntPtr) instance Semiring CIntPtr
deriving via (WrappedNum CSUSeconds) instance Semiring CSUSeconds
deriving via (WrappedNum CUSeconds) instance Semiring CUSeconds
deriving via (WrappedNum CTime) instance Semiring CTime
deriving via (WrappedNum CClock) instance Semiring CClock
deriving via (WrappedNum CSigAtomic) instance Semiring CSigAtomic
deriving via (WrappedNum CWchar) instance Semiring CWchar
deriving via (WrappedNum CSize) instance Semiring CSize
deriving via (WrappedNum CPtrdiff) instance Semiring CPtrdiff
deriving via (WrappedNum CDouble) instance Semiring CDouble
deriving via (WrappedNum CFloat) instance Semiring CFloat
deriving via (WrappedNum CULLong) instance Semiring CULLong
deriving via (WrappedNum CLLong) instance Semiring CLLong
deriving via (WrappedNum CULong) instance Semiring CULong
deriving via (WrappedNum CLong) instance Semiring CLong
deriving via (WrappedNum CUInt) instance Semiring CUInt
deriving via (WrappedNum CInt) instance Semiring CInt
deriving via (WrappedNum CUShort) instance Semiring CUShort
deriving via (WrappedNum CShort) instance Semiring CShort
deriving via (WrappedNum CUChar) instance Semiring CUChar
deriving via (WrappedNum CSChar) instance Semiring CSChar
deriving via (WrappedNum CChar) instance Semiring CChar
deriving via (WrappedNum IntPtr) instance Semiring IntPtr
deriving via (WrappedNum WordPtr) instance Semiring WordPtr

#ifdef HTYPE_CC_T
deriving via (WrappedNum CCc) instance Semiring CCc
#endif
#ifdef HTYPE_DEV_T
deriving via (WrappedNum CDev) instance Semiring CDev
#endif
#ifdef HTYPE_GID_T
deriving via (WrappedNum CGid) instance Semiring CGid
#endif
#ifdef HTYPE_INO_T
deriving via (WrappedNum CIno) instance Semiring CIno
#endif
#ifdef HTYPE_MODE_T
deriving via (WrappedNum CMode) instance Semiring CMode
#endif
#ifdef HTYPE_NLINK_T
deriving via (WrappedNum CNlink) instance Semiring CNlink
#endif
#ifdef HTYPE_OFF_T
deriving via (WrappedNum COff) instance Semiring COff
#endif
#ifdef HTYPE_PID_T
deriving via (WrappedNum CPid) instance Semiring CPid
#endif
#ifdef HTYPE_RLIM_T
deriving via (WrappedNum CRLim) instance Semiring CRLim
#endif
#ifdef HTYPE_SPEED_T
deriving via (WrappedNum CSpeed) instance Semiring CSpeed
#endif
#ifdef HTYPE_SSIZE_T
deriving via (WrappedNum CSsize) instance Semiring CSsize
#endif
#ifdef HTYPE_TCFLAG_T
deriving via (WrappedNum CTcflag) instance Semiring CTcflag
#endif
#ifdef HTYPE_UID_T
deriving via (WrappedNum CUid) instance Semiring CUid
#endif
deriving via (WrappedNum Fd) instance Semiring Fd

deriving via (WrappedNum Natural) instance Semiring Natural
#else
-- Integral and fieldlike instances
$(let
  deriveSemiring :: Q Type -> Q [Dec]
  deriveSemiring ty = [d|
      instance Semiring $ty where
         zero  = 0
         one   = 1
         plus  x y = (Num.+) x y
         times x y = (Num.*) x y
         fromNatural = Real.fromIntegral
         {-# INLINE zero #-}
         {-# INLINE one  #-}
         {-# INLINE plus #-}
         {-# INLINE times #-}
         {-# INLINE fromNatural #-}
      |]

  in P.concat P.<$> P.traverse deriveSemiring
   [[t|Int|]
   ,[t|Int8|]
   ,[t|Int16|]
   ,[t|Int32|]
   ,[t|Int64|]
   ,[t|Integer|]
   ,[t|Word|]
   ,[t|Word8|]
   ,[t|Word16|]
   ,[t|Word32|]
   ,[t|Word64|]
   ,[t|Float|]
   ,[t|Double|]
   ,[t|CUIntMax|]
   ,[t|CIntMax|]
   ,[t|CUIntPtr|]
   ,[t|CIntPtr|]
   ,[t|CSUSeconds|]
   ,[t|CUSeconds|]
   ,[t|CTime|]
   ,[t|CClock|]
   ,[t|CSigAtomic|]
   ,[t|CWchar|]
   ,[t|CSize|]
   ,[t|CPtrdiff|]
   ,[t|CDouble|]
   ,[t|CFloat|]
   ,[t|CULLong|]
   ,[t|CLLong|]
   ,[t|CULong|]
   ,[t|CLong|]
   ,[t|CUInt|]
   ,[t|CInt|]
   ,[t|CUShort|]
   ,[t|CShort|]
   ,[t|CUChar|]
   ,[t|CSChar|]
   ,[t|CChar|]
   ,[t|IntPtr|]
   ,[t|WordPtr|]

#ifdef HTYPE_CC_T
   ,[t|CCc|]
#endif
#ifdef HTYPE_DEV_T
   ,[t|CDev|]
#endif
#ifdef HTYPE_GID_T
   ,[t|CGid|]
#endif
#ifdef HTYPE_INO_T
   ,[t|CIno|]
#endif
#ifdef HTYPE_MODE_T
   ,[t|CMode|]
#endif
#ifdef HTYPE_NLINK_T
   ,[t|CNlink|]
#endif
#ifdef HTYPE_OFF_T
   ,[t|COff|]
#endif
#ifdef HTYPE_PID_T
   ,[t|CPid|]
#endif
#ifdef HTYPE_RLIM_T
   ,[t|CRLim|]
#endif
#ifdef HTYPE_SPEED_T
   ,[t|CSpeed|]
#endif
#ifdef HTYPE_SSIZE_T
   ,[t|CSsize|]
#endif
#ifdef HTYPE_TCFLAG_T
   ,[t|CTcflag|]
#endif
#ifdef HTYPE_UID_T
   ,[t|CUid|]
#endif
   ,[t|Fd|]

   ,[t|Natural|]
   ])
#endif

#if MIN_VERSION_base(4,12,0)
deriving via (WrappedNum Int) instance Ring Int
deriving via (WrappedNum Int8) instance Ring Int8
deriving via (WrappedNum Int16) instance Ring Int16
deriving via (WrappedNum Int32) instance Ring Int32
deriving via (WrappedNum Int64) instance Ring Int64
deriving via (WrappedNum Integer) instance Ring Integer
deriving via (WrappedNum Word) instance Ring Word
deriving via (WrappedNum Word8) instance Ring Word8
deriving via (WrappedNum Word16) instance Ring Word16
deriving via (WrappedNum Word32) instance Ring Word32
deriving via (WrappedNum Word64) instance Ring Word64
deriving via (WrappedNum Float) instance Ring Float
deriving via (WrappedNum Double) instance Ring Double
deriving via (WrappedNum CUIntMax) instance Ring CUIntMax
deriving via (WrappedNum CIntMax) instance Ring CIntMax
deriving via (WrappedNum CUIntPtr) instance Ring CUIntPtr
deriving via (WrappedNum CIntPtr) instance Ring CIntPtr
deriving via (WrappedNum CSUSeconds) instance Ring CSUSeconds
deriving via (WrappedNum CUSeconds) instance Ring CUSeconds
deriving via (WrappedNum CTime) instance Ring CTime
deriving via (WrappedNum CClock) instance Ring CClock
deriving via (WrappedNum CSigAtomic) instance Ring CSigAtomic
deriving via (WrappedNum CWchar) instance Ring CWchar
deriving via (WrappedNum CSize) instance Ring CSize
deriving via (WrappedNum CPtrdiff) instance Ring CPtrdiff
deriving via (WrappedNum CDouble) instance Ring CDouble
deriving via (WrappedNum CFloat) instance Ring CFloat
deriving via (WrappedNum CULLong) instance Ring CULLong
deriving via (WrappedNum CLLong) instance Ring CLLong
deriving via (WrappedNum CULong) instance Ring CULong
deriving via (WrappedNum CLong) instance Ring CLong
deriving via (WrappedNum CUInt) instance Ring CUInt
deriving via (WrappedNum CInt) instance Ring CInt
deriving via (WrappedNum CUShort) instance Ring CUShort
deriving via (WrappedNum CShort) instance Ring CShort
deriving via (WrappedNum CUChar) instance Ring CUChar
deriving via (WrappedNum CSChar) instance Ring CSChar
deriving via (WrappedNum CChar) instance Ring CChar
deriving via (WrappedNum IntPtr) instance Ring IntPtr
deriving via (WrappedNum WordPtr) instance Ring WordPtr

#ifdef HTYPE_CC_T
deriving via (WrappedNum CCc) instance Ring CCc
#endif
#ifdef HTYPE_DEV_T
deriving via (WrappedNum CDev) instance Ring CDev
#endif
#ifdef HTYPE_GID_T
deriving via (WrappedNum CGid) instance Ring CGid
#endif
#ifdef HTYPE_INO_T
deriving via (WrappedNum CIno) instance Ring CIno
#endif
#ifdef HTYPE_MODE_T
deriving via (WrappedNum CMode) instance Ring CMode
#endif
#ifdef HTYPE_NLINK_T
deriving via (WrappedNum CNlink) instance Ring CNlink
#endif
#ifdef HTYPE_OFF_T
deriving via (WrappedNum COff) instance Ring COff
#endif
#ifdef HTYPE_PID_T
deriving via (WrappedNum CPid) instance Ring CPid
#endif
#ifdef HTYPE_RLIM_T
deriving via (WrappedNum CRLim) instance Ring CRLim
#endif
#ifdef HTYPE_SPEED_T
deriving via (WrappedNum CSpeed) instance Ring CSpeed
#endif
#ifdef HTYPE_SSIZE_T
deriving via (WrappedNum CSsize) instance Ring CSsize
#endif
#ifdef HTYPE_TCFLAG_T
deriving via (WrappedNum CTcflag) instance Ring CTcflag
#endif
#ifdef HTYPE_UID_T
deriving via (WrappedNum CUid) instance Ring CUid
#endif
deriving via (WrappedNum Fd) instance Ring Fd
#else
$(let
  deriveRing :: Q Type -> Q [Dec]
  deriveRing ty = [d|
      instance Ring $ty where
        negate = Num.negate
        {-# INLINE negate #-}
      |]

  in P.concat P.<$> P.traverse deriveRing
    [[t|Int|]
    ,[t|Int8|]
    ,[t|Int16|]
    ,[t|Int32|]
    ,[t|Int64|]
    ,[t|Integer|]
    ,[t|Word|]
    ,[t|Word8|]
    ,[t|Word16|]
    ,[t|Word32|]
    ,[t|Word64|]
    ,[t|Float|]
    ,[t|Double|]
    ,[t|CUIntMax|]
    ,[t|CIntMax|]
    ,[t|CUIntPtr|]
    ,[t|CIntPtr|]
    ,[t|CSUSeconds|]
    ,[t|CUSeconds|]
    ,[t|CTime|]
    ,[t|CClock|]
    ,[t|CSigAtomic|]
    ,[t|CWchar|]
    ,[t|CSize|]
    ,[t|CPtrdiff|]
    ,[t|CDouble|]
    ,[t|CFloat|]
    ,[t|CULLong|]
    ,[t|CLLong|]
    ,[t|CULong|]
    ,[t|CLong|]
    ,[t|CUInt|]
    ,[t|CInt|]
    ,[t|CUShort|]
    ,[t|CShort|]
    ,[t|CUChar|]
    ,[t|CSChar|]
    ,[t|CChar|]
    ,[t|IntPtr|]
    ,[t|WordPtr|]

#ifdef HTYPE_CC_T
    ,[t|CCc|]
#endif
#ifdef HTYPE_DEV_T
    ,[t|CDev|]
#endif
#ifdef HTYPE_GID_T
    ,[t|CGid|]
#endif
#ifdef HTYPE_INO_T
    ,[t|CIno|]
#endif
#ifdef HTYPE_MODE_T
    ,[t|CMode|]
#endif
#ifdef HTYPE_NLINK_T
    ,[t|CNlink|]
#endif
#ifdef HTYPE_OFF_T
    ,[t|COff|]
#endif
#ifdef HTYPE_PID_T
    ,[t|CPid|]
#endif
#ifdef HTYPE_RLIM_T
    ,[t|CRLim|]
#endif
#ifdef HTYPE_SPEED_T
    ,[t|CSpeed|]
#endif
#ifdef HTYPE_SSIZE_T
    ,[t|CSsize|]
#endif
#ifdef HTYPE_TCFLAG_T
    ,[t|CTcflag|]
#endif
#ifdef HTYPE_UID_T
    ,[t|CUid|]
#endif
    ,[t|Fd|]
    ])
#endif