-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Fast type-safe modular arithmetic -- -- Modular arithmetic, promoting moduli to the type level, with an -- emphasis on performance. Originally part of arithmoi package. @package mod @version 0.1.0.0 -- | Modular arithmetic, promoting moduli to the type level, with an -- emphasis on performance. Originally part of arithmoi package. module Data.Mod -- | This data type represents integers modulo m, equipped with -- useful instances. -- -- For example, 3 :: Mod 10 stands for the class of integers -- congruent to 3 modulo 10: …−17, −7, 3, 13, 23… -- --
--   >>> :set -XDataKinds
--   
--   >>> 3 + 8 :: Mod 10
--   (1 `modulo` 10) -- because 3 + 8 = 11 ≡ 1 (mod 10)
--   
-- -- Warning: division by residue, which is not coprime with -- the modulo, throws DivideByZero. Consider using -- invertMod for non-prime moduli. data Mod (m :: Nat) -- | The canonical representative of the residue class, always between 0 -- and m - 1 inclusively. unMod :: Mod m -> Natural -- | If an argument is coprime with the modulo, return its modular -- inverse. Otherwise return Nothing. -- --
--   >>> :set -XDataKinds
--   
--   >>> invertMod 3 :: Mod 10
--   Just (7 `modulo` 10) -- because 3 * 7 = 21 ≡ 1 (mod 10)
--   
--   >>> invertMod 4 :: Mod 10
--   Nothing -- because 4 and 10 are not coprime
--   
invertMod :: KnownNat m => Mod m -> Maybe (Mod m) -- | Drop-in replacement for ^ with much better performance. -- Negative powers are allowed, but may throw DivideByZero, if an -- argument is not coprime with the modulo. -- -- Building with -O triggers a rewrite rule ^ = -- ^%. -- --
--   >>> :set -XDataKinds
--   
--   >>> 3 ^% 4 :: Mod 10
--   (1 `modulo` 10) -- because 3 ^ 4 = 81 ≡ 1 (mod 10)
--   
--   >>> 3 ^% (-1) :: Mod 10
--   (7 `modulo` 10) -- because 3 * 7 = 21 ≡ 1 (mod 10)
--   
--   >>> 4 ^% (-1) :: Mod 10
--   (*** Exception: divide by zero -- because 4 and 10 are not coprime
--   
(^%) :: (KnownNat m, Integral a) => Mod m -> a -> Mod m infixr 8 ^% instance GHC.Generics.Generic (Data.Mod.Mod m) instance GHC.Classes.Ord (Data.Mod.Mod m) instance GHC.Classes.Eq (Data.Mod.Mod m) instance Control.DeepSeq.NFData (Data.Mod.Mod m) instance GHC.TypeNats.KnownNat m => GHC.Show.Show (Data.Mod.Mod m) instance GHC.TypeNats.KnownNat m => GHC.Enum.Enum (Data.Mod.Mod m) instance GHC.TypeNats.KnownNat m => GHC.Enum.Bounded (Data.Mod.Mod m) instance GHC.TypeNats.KnownNat m => GHC.Num.Num (Data.Mod.Mod m) instance GHC.TypeNats.KnownNat m => Data.Semiring.Semiring (Data.Mod.Mod m) instance GHC.TypeNats.KnownNat m => Data.Semiring.Ring (Data.Mod.Mod m) instance GHC.TypeNats.KnownNat m => GHC.Real.Fractional (Data.Mod.Mod m) instance GHC.TypeNats.KnownNat m => Data.Euclidean.GcdDomain (Data.Mod.Mod m) instance GHC.TypeNats.KnownNat m => Data.Euclidean.Euclidean (Data.Mod.Mod m) instance GHC.TypeNats.KnownNat m => Data.Euclidean.Field (Data.Mod.Mod m)