-- |-- Module: Math.NumberTheory.Moduli.Class-- Copyright: (c) 2017 Andrew Lelechenko-- Licence: MIT-- Maintainer: Andrew Lelechenko <andrew.lelechenko@gmail.com>---- Safe modular arithmetic with modulo on type level.--{-# LANGUAGE DataKinds #-}{-# LANGUAGE GADTs #-}{-# LANGUAGE KindSignatures #-}{-# LANGUAGE RankNTypes #-}{-# LANGUAGE ScopedTypeVariables #-}moduleMath.NumberTheory.Moduli.Class(-- * Known moduloMod,getVal ,getNatVal ,getMod ,getNatMod ,invertMod,powMod ,(^%)-- * Multiplicative group,MultMod ,multElement ,isMultElement ,invertGroup -- * Unknown modulo,SomeMod (..),modulo ,invertSomeMod ,powSomeMod -- * Re-exported from GHC.TypeNats.Compat,KnownNat)whereimportData.ModimportGHC.NaturalimportGHC.TypeNats(KnownNat,natVal)importMath.NumberTheory.Moduli.Multiplicative importMath.NumberTheory.Moduli.SomeMod -- | Linking type and value levels: extract modulo @m@ as a value.getMod ::KnownNatm =>Modm ->IntegergetMod :: forall (m :: Nat). KnownNat m => Mod m -> Integer getMod =Nat -> Integer forall a. Integral a => a -> Integer toInteger(Nat -> Integer) -> (Mod m -> Nat) -> Mod m -> Integer forall b c a. (b -> c) -> (a -> b) -> a -> c .Mod m -> Nat forall (n :: Nat) (proxy :: Nat -> *). KnownNat n => proxy n -> Nat natVal{-# INLINEgetMod #-}-- | Linking type and value levels: extract modulo @m@ as a value.getNatMod ::KnownNatm =>Modm ->NaturalgetNatMod :: forall (m :: Nat). KnownNat m => Mod m -> Nat getNatMod =Mod m -> Nat forall (n :: Nat) (proxy :: Nat -> *). KnownNat n => proxy n -> Nat natVal{-# INLINEgetNatMod #-}-- | The canonical representative of the residue class, always between 0 and m-1 inclusively.getVal ::Modm ->IntegergetVal :: forall (m :: Nat). Mod m -> Integer getVal =Nat -> Integer forall a. Integral a => a -> Integer toInteger(Nat -> Integer) -> (Mod m -> Nat) -> Mod m -> Integer forall b c a. (b -> c) -> (a -> b) -> a -> c .Mod m -> Nat forall (m :: Nat). Mod m -> Nat unMod{-# INLINEgetVal #-}-- | The canonical representative of the residue class, always between 0 and m-1 inclusively.getNatVal ::Modm ->NaturalgetNatVal :: forall (m :: Nat). Mod m -> Nat getNatVal =Mod m -> Nat forall (m :: Nat). Mod m -> Nat unMod{-# INLINEgetNatVal #-}-- | Synonym of '(^%)'.powMod ::(KnownNatm ,Integrala )=>Modm ->a ->Modm powMod :: forall (m :: Nat) a. (KnownNat m, Integral a) => Mod m -> a -> Mod m powMod =Mod m -> a -> Mod m forall (m :: Nat) a. (KnownNat m, Integral a) => Mod m -> a -> Mod m (^%){-# INLINEpowMod #-}