smart-math-0.1: Mathematical smart constructors
Safe HaskellNone
LanguageHaskell2010

Numeric.Data.Internal.Utils

Description

Internal utils.

Synopsis

Safe modular arithmetic

Algebra-simple

checkModBoundAlgebra Source #

Arguments

:: (ToInteger a, MaybeUpperBounded a, Typeable a) 
=> a

The type a whose upper bound must be large enough to accommodate modular arithmetic within modulus n. This would be a Proxy except we get a better error message for the value itself.

-> Integer

The modulus n that should satisfy n <= max(a).

-> Maybe String 

Verifies that the type A is large enough to fit the modulus. Returns Nothing if the check succeeds or a String error message if the check fails.

modSafeAddAlgebra Source #

Arguments

:: (ASemigroup a, FromInteger a, MEuclidean a, MaybeUpperBounded a, ToInteger a) 
=> a

x

-> a

y

-> a

n (modulus)

-> a 

Performs modular addition, accounting for rounding in the type itself.

modSafeMultAlgebra Source #

Arguments

:: (FromInteger a, MEuclidean a, MaybeUpperBounded a, ToInteger a) 
=> a

x

-> a

y

-> a

n (modulus)

-> a 

Performs modular multiplication, accounting for rounding in the type itself.

modSafeSubAlgebra Source #

Arguments

:: (ASemigroup a, FromInteger a, MEuclidean a, ToInteger a, MaybeUpperBounded a) 
=> a

x

-> a

y

-> a

n (modulus)

-> a 

Performs modular subtraction, accounting for rounding in the type itself.

Optics

rmatching :: (Is (ReversedOptic k) An_AffineTraversal, ReversibleOptic k) => Optic k NoIx b a t s -> s -> Either t a Source #

Reversed matching. Useful with smart-constructor optics.

Since: 0.1