-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | A type for integers modulo some constant. -- -- A convenient type for working with integers modulo some constant. It -- saves you from manually wrapping numeric operations all over the place -- and prevents a range of simple mistakes. Integer Mod 7 -- is the type of integers (mod 7) backed by Integer. We also -- have some cute syntax for these types like ℤ/7 for integers -- modulo 7. @package modular-arithmetic @version 2.0.0.3 -- | Types for working with integers modulo some constant. module Data.Modular -- | Wraps an underlying Integeral type i in a newtype -- annotated with the bound n. data i `Mod` (n :: Nat) -- | The modulus has to be a non-zero type-level natural number. type Modulus n = (KnownNat n, 1 <= n) -- | Extract the underlying integral value from a modular type. -- --
-- >>> unMod (10 :: ℤ/4) -- 2 --unMod :: (i `Mod` n) -> i -- | Injects a value of the underlying type into the modulus type, wrapping -- as appropriate. -- -- If n is ambiguous, you can specify it with -- TypeApplications: -- --
-- >>> toMod @6 10 -- 4 ---- -- Note that n cannot be 0. toMod :: forall n i. (Integral i, Modulus n) => i -> i `Mod` n -- | Wraps an integral number, converting between integral types. toMod' :: forall n i j. (Integral i, Integral j, Modulus n) => i -> j `Mod` n -- | The modular inverse. -- --
-- >>> inv 3 :: Maybe (ℤ/7) -- Just 5 -- -- >>> 3 * 5 :: ℤ/7 -- 1 ---- -- Note that only numbers coprime to n have an inverse modulo -- n: -- --
-- >>> inv 6 :: Maybe (ℤ/15) -- Nothing --inv :: forall n i. (Modulus n, Integral i) => (i / n) -> Maybe (i / n) -- | A synonym for Mod, inspired by the ℤ/n syntax from -- mathematics. type (/) = Mod -- | A synonym for Integer, also inspired by the ℤ/n syntax. type ℤ = Integer -- | Convert an integral number i into a Mod value -- with the type-level modulus n specified with a proxy -- argument. -- -- This lets you use toMod without TypeApplications in -- contexts where n is ambiguous. modVal :: forall i proxy n. (Integral i, Modulus n) => i -> proxy n -> Mod i n -- | A modular number with an unknown modulus. -- -- Conceptually SomeMod i = ∃n. i/n. data SomeMod i -- | Convert an integral number i into SomeMod -- with the modulus given at runtime. -- -- That is, given i :: ℤ, someModVal i modulus is -- equivalent to i :: ℤ/modulus except we don't know -- modulus statically. -- --
-- >>> someModVal 10 4 -- Just (someModVal 2 4) ---- -- Will return Nothing if the modulus is 0 or negative: -- --
-- >>> someModVal 10 (-10) -- Nothing ---- --
-- >>> someModVal 10 0 -- Nothing --someModVal :: Integral i => i -> Integer -> Maybe (SomeMod i) instance GHC.Classes.Ord i => GHC.Classes.Ord (Data.Modular.Mod i n) instance GHC.Classes.Eq i => GHC.Classes.Eq (Data.Modular.Mod i n) instance GHC.Show.Show i => GHC.Show.Show (Data.Modular.SomeMod i) instance (GHC.Read.Read i, GHC.Real.Integral i, Data.Modular.Modulus n) => GHC.Read.Read (Data.Modular.Mod i n) instance (GHC.Real.Integral i, Data.Modular.Modulus n) => GHC.Num.Num (Data.Modular.Mod i n) instance (GHC.Real.Integral i, Data.Modular.Modulus n) => GHC.Enum.Enum (Data.Modular.Mod i n) instance (GHC.Real.Integral i, Data.Modular.Modulus n) => GHC.Enum.Bounded (Data.Modular.Mod i n) instance (GHC.Real.Integral i, Data.Modular.Modulus n) => GHC.Real.Real (Data.Modular.Mod i n) instance (GHC.Real.Integral i, Data.Modular.Modulus n) => GHC.Real.Fractional (Data.Modular.Mod i n) instance GHC.Show.Show i => GHC.Show.Show (Data.Modular.Mod i n)