haskus-binary-1.5: Haskus binary format manipulation

Safe HaskellNone
LanguageHaskell2010

Haskus.Number.NaturalRange

Description

A natural number in a specified range (fixed and checked at compile-time)

Synopsis

Documentation

data NatRange (f :: Nat) (t :: Nat) Source #

A natural number in the specified range

Instances
(KnownNat (t - f), KnownNat t, KnownNat f, Num (BitNatWord (NatBitCount ((t - f) + 1))), Integral (BitNatWord (NatBitCount ((t - f) + 1)))) => Show (NatRange f t) Source #

Show instance for natural range

Instance details

Defined in Haskus.Number.NaturalRange

Methods

showsPrec :: Int -> NatRange f t -> ShowS #

show :: NatRange f t -> String #

showList :: [NatRange f t] -> ShowS #

pattern NatRange :: forall (f :: Nat) (t :: Nat). MakeNatRange f t => Natural -> NatRange f t Source #

Natural range pattern

>>> NatRange @10 @12 11
NatRange @10 @12 11

natRange :: forall (n :: Nat) f t. (MakeNatRange f t, CheckInRange f t n, KnownNat n) => NatRange f t Source #

Create a value in a Natural range

safeMakeNatRange :: forall f t. MakeNatRange f t => Natural -> Maybe (NatRange f t) Source #

Create a value in a Natural range (check validity)

makeNatRange :: forall f t. MakeNatRange f t => Natural -> NatRange f t Source #

Create a value in a Natural range (check validity and throw on error)

unsafeMakeNatRange :: forall f t. MakeNatRange f t => Natural -> NatRange f t Source #

Create a value in a Natural range

widenNatRange :: forall f2 t2 f1 t1. WidenNatRange f1 t1 f2 t2 => NatRange f1 t1 -> NatRange f2 t2 Source #

Widen a natural

>>> let a = NatRange @18 @100 25
>>> widenNatRange @16 @200 a
NatRange @16 @200 25

(.++.) :: (MakeNatRange f1 t1, MakeNatRange f2 t2, MakeNatRange (f1 + f2) (t1 + t2)) => NatRange f1 t1 -> NatRange f2 t2 -> NatRange (f1 + f2) (t1 + t2) Source #

Add two natural ranges

>>> NatRange @2 @4 3 .++. NatRange @7 @17 13
NatRange @9 @21 16