typed-digits-0.1.0.0: Digits, indexed by their base at the type level

Portabilityportable
Safe HaskellNone
LanguageHaskell98

Data.TypedDigits

Contents

Description

Description

Digits, indexed by their base at the type level.

Synopsis

Documentation

data Digit (base :: Nat) Source #

digits, indexed by their base at the type level

Instances
KnownNat base => Bounded (Digit base) Source # 
Instance details

Defined in Data.TypedDigits.Internal

Methods

minBound :: Digit base #

maxBound :: Digit base #

KnownNat base => Enum (Digit base) Source # 
Instance details

Defined in Data.TypedDigits.Internal

Methods

succ :: Digit base -> Digit base #

pred :: Digit base -> Digit base #

toEnum :: Int -> Digit base #

fromEnum :: Digit base -> Int #

enumFrom :: Digit base -> [Digit base] #

enumFromThen :: Digit base -> Digit base -> [Digit base] #

enumFromTo :: Digit base -> Digit base -> [Digit base] #

enumFromThenTo :: Digit base -> Digit base -> Digit base -> [Digit base] #

Eq (Digit base) Source # 
Instance details

Defined in Data.TypedDigits.Internal

Methods

(==) :: Digit base -> Digit base -> Bool #

(/=) :: Digit base -> Digit base -> Bool #

Ord (Digit base) Source # 
Instance details

Defined in Data.TypedDigits.Internal

Methods

compare :: Digit base -> Digit base -> Ordering #

(<) :: Digit base -> Digit base -> Bool #

(<=) :: Digit base -> Digit base -> Bool #

(>) :: Digit base -> Digit base -> Bool #

(>=) :: Digit base -> Digit base -> Bool #

max :: Digit base -> Digit base -> Digit base #

min :: Digit base -> Digit base -> Digit base #

KnownNat base => Show (Digit base) Source # 
Instance details

Defined in Data.TypedDigits.Internal

Methods

showsPrec :: Int -> Digit base -> ShowS #

show :: Digit base -> String #

showList :: [Digit base] -> ShowS #

Constructing Digits

digit :: forall base. KnownNat base => Int -> Maybe (Digit base) Source #

digit x: construct a digit. 0 <= x < base must hold true.

Nicer if TypeApplications is enabled, then you can say:

>>> :set -XDataKinds
>>> :set -XTypeApplications
>>> digit @9 8
Just 8 (base 9)

digit' :: KnownNat base => Int -> Digit base Source #

Like digit, but throws an ErrorCall if the value is out of range.

sample usage:

>>> :set -XDataKinds
>>> :set -XTypeApplications
>>> digit' @9 7
7 (base 9)

Querying Digits

getVal :: Digit base -> Int Source #

getBase :: KnownNat base => Digit base -> Int Source #

getBase d: return the base of the digit d

getBaseT :: forall a base. KnownNat base => a base -> Int Source #

getBaseT p: if p is of some type a base, then reflect the base into a value.

Useful for getting the base, just given a Proxy; e.g.:

>>> :set -XDataKinds
>>> :set -XTypeApplications
>>> let p = Proxy :: Proxy 3
>>> getBaseT p
3

Arithmetic operations on Digits

(<+>) :: KnownNat base => Digit base -> Digit base -> Digit base Source #

Making Digit an instance of Num does not seem sensible, but it's nevertheless useful to be able to add and subtract digits, so <+> and <-> are provided for this.

a + b: Add a and b. Throws an ErrorCall if the result is out of range.

(<->) :: KnownNat base => Digit base -> Digit base -> Digit base Source #

a - b: Subtract b from a. Throws an ErrorCall if the result is out of range.

class KnownNat (n :: Nat) #

This class gives the integer associated with a type-level natural. There are instances of the class for every concrete literal: 0, 1, 2, etc.

Since: base-4.7.0.0

Minimal complete definition

natSing