A type for integers modulo some constant.

Latest on Hackage:

This package is not currently in any snapshots. If you're interested in using it, we recommend adding it to Stackage Nightly. Doing so will make builds more reliable, and allow to host generated Haddocks.

BSD3 licensed and maintained by Tikhon Jelvis

Modular Arithmetic

Hackage package Build Status

This package provides a type for integers modulo some constant, usually written as ℤ/n.

Here is a quick example:

>>> 10 * 11 :: ℤ/7

It also works correctly with negative numeric literals:

>>> (-10) * 11 :: ℤ/7

Modular division is an inverse of modular multiplication. It is defined when divisor is coprime to modulus:

>>> 7 `div` 3 :: ℤ/16
>>> 3 * 13 :: ℤ/16


  • fixed a name clash with GHC.TypeLits for base >= 4.11.0

  • exported the / type operator with ExplicitNamespaces enabled to support GHC 8. Should be backwards compatible through GHC 7.6.

  • added a basic test suite with doctests

  • changed Integral implementation: quotRem now uses modular inversion!
  • added inv for modular inversion
  • added SomeMod data type for modular number with unknown modulus
  • added modVal and someModVal helpers similar to ones in GHC.TypeLits
Depends on 1 package:
Used by 3 packages:
comments powered byDisqus