Safe Haskell | None |
---|---|
Language | Haskell2010 |
Modular arithmetic
Mod m i is an integer of type i modulo m. m will usually be a compile-time constant. If m is not known at compile time, Mod can still be used via GHC.TypeNats.SomeNat. m must be >= 2 and fit in the type i. Integer operations on i for values in [0..m-1] must not overflow. Examples to avoid are using (-) with a word type or using (*) with a large enough mod that (m-1)^2 oveflows.
This is a very general type, for something simpler see MInt.hs.
Instances of Eq, Num, Fractional exist for Mod m i. All the usual operations take O(1) time, except for recip which takes O(log n) time. This assumes Integral i methods take O(1) time. An instance of Enum exists for MInt. The enum is cyclic, it wraps to 0 after m-1. Unboxed array support is available via Unbox.
Documentation
newtype Mod (m :: Nat) i Source #
Type for modular arithmetic modulo m with underlying type i.
Instances
(KnownNat m, Integral i) => Enum (Mod m i) Source # | |
Eq i => Eq (Mod m i) Source # | |
(KnownNat m, Integral i) => Fractional (Mod m i) Source # | |
(KnownNat m, Integral i) => Num (Mod m i) Source # | |
Ord i => Ord (Mod m i) Source # | |
Show i => Show (Mod m i) Source # | |
NFData i => NFData (Mod m i) Source # | |
Unbox (Mod m i) Source # | |
type Unboxed (Mod m i) Source # | |