| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
Numeric.Data.ModN.Internal
Description
Provides the ModN type for modular arithmetic.
Since: 0.1
Synopsis
- newtype ModN (n :: Nat) a where
- UnsafeModN a
- pattern MkModN :: a -> ModN n a
- mkModN :: forall (n :: Nat) a. (FromInteger a, ToInteger a, KnownNat n, MaybeUpperBounded a, MEuclidean a, Typeable a) => a -> Either String (ModN n a)
- unsafeModN :: forall (n :: Nat) a. (FromInteger a, HasCallStack, KnownNat n, MaybeUpperBounded a, MEuclidean a, ToInteger a, Typeable a) => a -> ModN n a
- reallyUnsafeModN :: forall (n :: Nat) a. (FromInteger a, KnownNat n, MEuclidean a) => a -> ModN n a
- errMsg :: String -> String
Type
newtype ModN (n :: Nat) a Source #
Newtype wrapper that represents \( \mathbb{Z}/n\mathbb{Z} \).
ModN is a Ring i.e. supports addition, subtraction,
and multiplication.
When constructing a we must verify that the type ModN n aa is large
enough to accommodate n, hence the possible failure.
Examples
>>>import Data.Text.Display (display)>>>display $ unsafeModN @7 10"3 (mod 7)"
Since: 0.1
Constructors
| UnsafeModN a |
Bundled Patterns
| pattern MkModN :: a -> ModN n a | Bidirectional pattern synonym for Since: 0.1 |
Instances
Creation
mkModN :: forall (n :: Nat) a. (FromInteger a, ToInteger a, KnownNat n, MaybeUpperBounded a, MEuclidean a, Typeable a) => a -> Either String (ModN n a) Source #
Constructor for ModN.
Examples
>>>mkModN @5 7Right (MkModN 2 (mod 5))
>>>mkModN @10 7Right (MkModN 7 (mod 10))
>>>mkModN @128 (9 :: Int8)Left "Type 'Int8' has a maximum size of 127. This is not large enough to safely implement mod 128."
Since: 0.1
unsafeModN :: forall (n :: Nat) a. (FromInteger a, HasCallStack, KnownNat n, MaybeUpperBounded a, MEuclidean a, ToInteger a, Typeable a) => a -> ModN n a Source #
Variant of mkModN that throws an error when type a is not
large enough to fit n.
WARNING: Partial
Examples
>>>unsafeModN @7 12MkModN 5 (mod 7)
Since: 0.1
reallyUnsafeModN :: forall (n :: Nat) a. (FromInteger a, KnownNat n, MEuclidean a) => a -> ModN n a Source #
This function reduces the argument modulo p but does not check
that n fits within a. Note that correct behavior requires this, so this
is dangerous. This is intended only for when we absolutely know n fits in
a and the check is undesirable for performance reasons. Exercise extreme
caution.
Since: 0.1