basement-0.0.12: Foundation scrap box of array & string
LicenseBSD-style
MaintainerVincent Hanquez <vincent@snarc.org>
Stabilityexperimental
Portabilityportable
Safe HaskellNone
LanguageHaskell2010

Basement.Types.OffsetSize

Description

 
Synopsis

Documentation

newtype Offset ty Source #

Offset in a data structure consisting of elements of type ty.

Int is a terrible backing type which is hard to get away from, considering that GHC/Haskell are mostly using this for offset. Trying to bring some sanity by a lightweight wrapping.

Constructors

Offset Int 

Instances

Instances details
TryFrom Int (Offset ty) Source # 
Instance details

Defined in Basement.From

Methods

tryFrom :: Int -> Maybe (Offset ty) Source #

From Word (Offset ty) Source # 
Instance details

Defined in Basement.From

Methods

from :: Word -> Offset ty Source #

Enum (Offset ty) Source # 
Instance details

Defined in Basement.Types.OffsetSize

Methods

succ :: Offset ty -> Offset ty Source #

pred :: Offset ty -> Offset ty Source #

toEnum :: Int -> Offset ty Source #

fromEnum :: Offset ty -> Int Source #

enumFrom :: Offset ty -> [Offset ty] Source #

enumFromThen :: Offset ty -> Offset ty -> [Offset ty] Source #

enumFromTo :: Offset ty -> Offset ty -> [Offset ty] Source #

enumFromThenTo :: Offset ty -> Offset ty -> Offset ty -> [Offset ty] Source #

Eq (Offset ty) Source # 
Instance details

Defined in Basement.Types.OffsetSize

Methods

(==) :: Offset ty -> Offset ty -> Bool Source #

(/=) :: Offset ty -> Offset ty -> Bool Source #

Num (Offset ty) Source # 
Instance details

Defined in Basement.Types.OffsetSize

Methods

(+) :: Offset ty -> Offset ty -> Offset ty Source #

(-) :: Offset ty -> Offset ty -> Offset ty Source #

(*) :: Offset ty -> Offset ty -> Offset ty Source #

negate :: Offset ty -> Offset ty Source #

abs :: Offset ty -> Offset ty Source #

signum :: Offset ty -> Offset ty Source #

fromInteger :: Integer -> Offset ty Source #

Ord (Offset ty) Source # 
Instance details

Defined in Basement.Types.OffsetSize

Methods

compare :: Offset ty -> Offset ty -> Ordering Source #

(<) :: Offset ty -> Offset ty -> Bool Source #

(<=) :: Offset ty -> Offset ty -> Bool Source #

(>) :: Offset ty -> Offset ty -> Bool Source #

(>=) :: Offset ty -> Offset ty -> Bool Source #

max :: Offset ty -> Offset ty -> Offset ty Source #

min :: Offset ty -> Offset ty -> Offset ty Source #

Show (Offset ty) Source # 
Instance details

Defined in Basement.Types.OffsetSize

Integral (Offset ty) Source # 
Instance details

Defined in Basement.Types.OffsetSize

IsNatural (Offset ty) Source # 
Instance details

Defined in Basement.Types.OffsetSize

Methods

toNatural :: Offset ty -> Natural Source #

IsIntegral (Offset ty) Source # 
Instance details

Defined in Basement.Types.OffsetSize

Methods

toInteger :: Offset ty -> Integer Source #

Subtractive (Offset ty) Source # 
Instance details

Defined in Basement.Types.OffsetSize

Associated Types

type Difference (Offset ty) Source #

Methods

(-) :: Offset ty -> Offset ty -> Difference (Offset ty) Source #

Additive (Offset ty) Source # 
Instance details

Defined in Basement.Types.OffsetSize

Methods

azero :: Offset ty Source #

(+) :: Offset ty -> Offset ty -> Offset ty Source #

scale :: IsNatural n => n -> Offset ty -> Offset ty Source #

NormalForm (Offset a) Source # 
Instance details

Defined in Basement.NormalForm

Methods

toNormalForm :: Offset a -> () Source #

type NatNumMaxBound (Offset x) Source # 
Instance details

Defined in Basement.Types.OffsetSize

type Difference (Offset ty) Source # 
Instance details

Defined in Basement.Types.OffsetSize

type Difference (Offset ty) = CountOf ty

type Offset8 = Offset Word8 Source #

Offset in bytes used for memory addressing (e.g. in a vector, string, ..)

offsetCast :: Proxy (a -> b) -> Offset a -> Offset b Source #

offsetSub :: Offset a -> Offset a -> Offset a Source #

subtract 2 CountOf values of the same type.

m need to be greater than n, otherwise negative count error ensue use the safer (-) version if unsure.

sizeCast :: Proxy (a -> b) -> CountOf a -> CountOf b Source #

sizeSub :: CountOf a -> CountOf a -> CountOf a Source #

subtract 2 CountOf values of the same type.

m need to be greater than n, otherwise negative count error ensue use the safer (-) version if unsure.

countOfRoundUp :: Int -> CountOf ty -> CountOf ty Source #

alignment need to be a power of 2

(+.) :: Offset ty -> Int -> Offset ty Source #

(.==#) :: Offset ty -> CountOf ty -> Bool Source #

newtype CountOf ty Source #

CountOf of a data structure.

More specifically, it represents the number of elements of type ty that fit into the data structure.

>>> length (fromList ['a', 'b', 'c', '🌟']) :: CountOf Char
CountOf 4

Same caveats as Offset apply here.

Constructors

CountOf Int 

Instances

Instances details
TryFrom Int (CountOf ty) Source # 
Instance details

Defined in Basement.From

Methods

tryFrom :: Int -> Maybe (CountOf ty) Source #

From Word (CountOf ty) Source # 
Instance details

Defined in Basement.From

Methods

from :: Word -> CountOf ty Source #

Enum (CountOf ty) Source # 
Instance details

Defined in Basement.Types.OffsetSize

Eq (CountOf ty) Source # 
Instance details

Defined in Basement.Types.OffsetSize

Methods

(==) :: CountOf ty -> CountOf ty -> Bool Source #

(/=) :: CountOf ty -> CountOf ty -> Bool Source #

Num (CountOf ty) Source # 
Instance details

Defined in Basement.Types.OffsetSize

Methods

(+) :: CountOf ty -> CountOf ty -> CountOf ty Source #

(-) :: CountOf ty -> CountOf ty -> CountOf ty Source #

(*) :: CountOf ty -> CountOf ty -> CountOf ty Source #

negate :: CountOf ty -> CountOf ty Source #

abs :: CountOf ty -> CountOf ty Source #

signum :: CountOf ty -> CountOf ty Source #

fromInteger :: Integer -> CountOf ty Source #

Ord (CountOf ty) Source # 
Instance details

Defined in Basement.Types.OffsetSize

Methods

compare :: CountOf ty -> CountOf ty -> Ordering Source #

(<) :: CountOf ty -> CountOf ty -> Bool Source #

(<=) :: CountOf ty -> CountOf ty -> Bool Source #

(>) :: CountOf ty -> CountOf ty -> Bool Source #

(>=) :: CountOf ty -> CountOf ty -> Bool Source #

max :: CountOf ty -> CountOf ty -> CountOf ty Source #

min :: CountOf ty -> CountOf ty -> CountOf ty Source #

Show (CountOf ty) Source # 
Instance details

Defined in Basement.Types.OffsetSize

Semigroup (CountOf ty) Source # 
Instance details

Defined in Basement.Types.OffsetSize

Methods

(<>) :: CountOf ty -> CountOf ty -> CountOf ty Source #

sconcat :: NonEmpty (CountOf ty) -> CountOf ty Source #

stimes :: Integral b => b -> CountOf ty -> CountOf ty Source #

Monoid (CountOf ty) Source # 
Instance details

Defined in Basement.Types.OffsetSize

Methods

mempty :: CountOf ty Source #

mappend :: CountOf ty -> CountOf ty -> CountOf ty Source #

mconcat :: [CountOf ty] -> CountOf ty Source #

Integral (CountOf ty) Source # 
Instance details

Defined in Basement.Types.OffsetSize

IsNatural (CountOf ty) Source # 
Instance details

Defined in Basement.Types.OffsetSize

Methods

toNatural :: CountOf ty -> Natural Source #

IsIntegral (CountOf ty) Source # 
Instance details

Defined in Basement.Types.OffsetSize

Methods

toInteger :: CountOf ty -> Integer Source #

Subtractive (CountOf ty) Source # 
Instance details

Defined in Basement.Types.OffsetSize

Associated Types

type Difference (CountOf ty) Source #

Methods

(-) :: CountOf ty -> CountOf ty -> Difference (CountOf ty) Source #

Additive (CountOf ty) Source # 
Instance details

Defined in Basement.Types.OffsetSize

Methods

azero :: CountOf ty Source #

(+) :: CountOf ty -> CountOf ty -> CountOf ty Source #

scale :: IsNatural n => n -> CountOf ty -> CountOf ty Source #

NormalForm (CountOf a) Source # 
Instance details

Defined in Basement.NormalForm

Methods

toNormalForm :: CountOf a -> () Source #

From (CountOf ty) Word Source # 
Instance details

Defined in Basement.From

Methods

from :: CountOf ty -> Word Source #

From (CountOf ty) Int Source # 
Instance details

Defined in Basement.From

Methods

from :: CountOf ty -> Int Source #

type NatNumMaxBound (CountOf x) Source # 
Instance details

Defined in Basement.Types.OffsetSize

type Difference (CountOf ty) Source # 
Instance details

Defined in Basement.Types.OffsetSize

type Difference (CountOf ty) = Maybe (CountOf ty)

natValCountOf :: forall n ty proxy. (KnownNat n, NatWithinBound (CountOf ty) n) => proxy n -> CountOf ty Source #

natValOffset :: forall n ty proxy. (KnownNat n, NatWithinBound (Offset ty) n) => proxy n -> Offset ty Source #