Safe Haskell | None |
---|---|

Language | Haskell98 |

This module provides types for working with integers modulo some constant.

This module uses some new Haskell features introduced in 7.6. In
particular, it needs `DataKinds`

and type literals
(GHC.TypeLits). The `TypeOperators`

extension is needed for the
nice infix syntax.

These types are created with the type constructor `Mod`

(or its synonym `/`

). To work with integers mod 7, you could write:

Int `Mod` 7 Integer `Mod` 7 Integer/7 ℤ/7

(The last is a synonym for `Integer`

provided by this library. In
Emacs, you can use the TeX input mode to type it with `\Bbb{Z}`

.)

All the usual typeclasses are defined for these types. You can also
get the constant using `bound`

or extract the underlying value
using `unMod`

.

Here is a quick example:

*Data.Modular> (10 :: ℤ/7) * (11 :: ℤ/7) 5

It also works correctly with negative numeric literals:

*Data.Modular> (-10 :: ℤ/7) * (11 :: ℤ/7) 2

# Documentation

toMod :: forall n i. (Integral i, KnownNat n) => i -> i `Mod` n Source

Wraps the underlying type into the modular type, wrapping as appropriate.

toMod' :: forall n i j. (Integral i, Integral j, KnownNat n) => i -> j `Mod` n Source

Wraps an integral number to a mod, converting between integral types.

The actual type, wrapping an underlying `Integeral`

type `i`

in a
newtype annotated with the bound.

(Integral i, KnownNat n) => Bounded (Mod i n) | |

(Integral i, KnownNat n) => Enum (Mod i n) | |

Eq i => Eq (Mod i n) | |

(Integral i, KnownNat n) => Integral (Mod i n) | |

(Integral i, KnownNat n) => Num (Mod i n) | |

Ord i => Ord (Mod i n) | |

(Read i, Integral i, KnownNat n) => Read (Mod i n) | |

(Integral i, KnownNat n) => Real (Mod i n) | |

Show i => Show (Mod i n) |