Safe Haskell | None |
---|---|
Language | Haskell2010 |
Synopsis
- data Ordinal m where
- numToOrdinal :: forall a m. (KnownNat m, Integral a) => a -> Maybe (Ordinal m)
- ordinalToNum :: Num a => Ordinal m -> a
- strengthenOrdinal :: forall n m. (KnownNat m, n <= m) => Ordinal n -> Ordinal m
- weakenOrdinal :: KnownNat m => Ordinal n -> Maybe (Ordinal m)
- _Ordinal :: (KnownNat n, Integral a) => Prism' a (Ordinal n)
Documentation
An Ordinal can only hold m different values, ususally corresponding to 0 .. m - 1. We store it here using a Proxy
of a type level number and use constraints to keep the required invariants.
Desprite represeting a number, Ordinal is not an instance of Num and many functions (such as negate) would only be partial
Instances
numToOrdinal :: forall a m. (KnownNat m, Integral a) => a -> Maybe (Ordinal m) Source #
Convert a normal integral to an ordinal. If it is outside the range (or= m), Nothing is returned.
ordinalToNum :: Num a => Ordinal m -> a Source #
Transform an ordinal to a given number