sized-grid-0.1.1.5: Multidimensional grids with sized specified at compile time

Safe HaskellNone
LanguageHaskell2010

SizedGrid.Ordinal

Synopsis

Documentation

data Ordinal m where Source #

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

Constructors

Ordinal :: (KnownNat n, KnownNat m, ((n + 1) <=? m) ~ True) => Proxy n -> Ordinal m 
Instances
(1 <= m, KnownNat m) => Bounded (Ordinal m) Source # 
Instance details

Defined in SizedGrid.Ordinal

(1 <= m, KnownNat m) => Enum (Ordinal m) Source # 
Instance details

Defined in SizedGrid.Ordinal

Methods

succ :: Ordinal m -> Ordinal m #

pred :: Ordinal m -> Ordinal m #

toEnum :: Int -> Ordinal m #

fromEnum :: Ordinal m -> Int #

enumFrom :: Ordinal m -> [Ordinal m] #

enumFromThen :: Ordinal m -> Ordinal m -> [Ordinal m] #

enumFromTo :: Ordinal m -> Ordinal m -> [Ordinal m] #

enumFromThenTo :: Ordinal m -> Ordinal m -> Ordinal m -> [Ordinal m] #

Eq (Ordinal m) Source # 
Instance details

Defined in SizedGrid.Ordinal

Methods

(==) :: Ordinal m -> Ordinal m -> Bool #

(/=) :: Ordinal m -> Ordinal m -> Bool #

Ord (Ordinal m) Source # 
Instance details

Defined in SizedGrid.Ordinal

Methods

compare :: Ordinal m -> Ordinal m -> Ordering #

(<) :: Ordinal m -> Ordinal m -> Bool #

(<=) :: Ordinal m -> Ordinal m -> Bool #

(>) :: Ordinal m -> Ordinal m -> Bool #

(>=) :: Ordinal m -> Ordinal m -> Bool #

max :: Ordinal m -> Ordinal m -> Ordinal m #

min :: Ordinal m -> Ordinal m -> Ordinal m #

Show (Ordinal m) Source # 
Instance details

Defined in SizedGrid.Ordinal

Methods

showsPrec :: Int -> Ordinal m -> ShowS #

show :: Ordinal m -> String #

showList :: [Ordinal m] -> ShowS #

KnownNat m => ToJSON (Ordinal m) Source # 
Instance details

Defined in SizedGrid.Ordinal

KnownNat m => ToJSONKey (Ordinal m) Source # 
Instance details

Defined in SizedGrid.Ordinal

KnownNat m => FromJSON (Ordinal m) Source # 
Instance details

Defined in SizedGrid.Ordinal

KnownNat m => FromJSONKey (Ordinal m) Source # 
Instance details

Defined in SizedGrid.Ordinal

(1 <= m, KnownNat m) => Random (Ordinal m) Source # 
Instance details

Defined in SizedGrid.Ordinal

Methods

randomR :: RandomGen g => (Ordinal m, Ordinal m) -> g -> (Ordinal m, g) #

random :: RandomGen g => g -> (Ordinal m, g) #

randomRs :: RandomGen g => (Ordinal m, Ordinal m) -> g -> [Ordinal m] #

randoms :: RandomGen g => g -> [Ordinal m] #

randomRIO :: (Ordinal m, Ordinal m) -> IO (Ordinal m) #

randomIO :: IO (Ordinal m) #

(1 <= n, KnownNat n) => IsCoord (Ordinal n) Source # 
Instance details

Defined in SizedGrid.Coord.Class

Associated Types

type CoordSized (Ordinal n) :: Nat Source #

type CoordFromNat (Ordinal n) :: Nat -> Type Source #

type CoordSized (Ordinal n) Source # 
Instance details

Defined in SizedGrid.Coord.Class

type CoordSized (Ordinal n) = n
type CoordFromNat (Ordinal n) Source # 
Instance details

Defined in SizedGrid.Coord.Class

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

strengthenOrdinal :: forall n m. (KnownNat m, n <= m) => Ordinal n -> Ordinal m Source #

_Ordinal :: (KnownNat n, Integral a) => Prism' a (Ordinal n) Source #

Convert between an ordinal and a usual number. This is a Prism as it may fail as Oridnals can only exist in a certain range.