si-bytes-0.1: Byte with type-level units (e.g. B, KB, MB, ...).
Safe HaskellNone
LanguageHaskell2010

Data.Bytes.Size

Description

Provides the Size type and typeclasses for converting between units.

Since: 0.1

Synopsis

Size Tags

data Size Source #

Byte units.

Since: 0.1

Constructors

B

Bytes

Since: 0.1

K

Kilobytes

Since: 0.1

M

Megabytes

Since: 0.1

G

Gigabytes

Since: 0.1

T

Terabytes

Since: 0.1

P

Petabytes

Since: 0.1

E

Exabytes

Since: 0.1

Z

Zettabytes

Since: 0.1

Y

Yottabytes

Since: 0.1

Instances

Instances details
NFData Size Source #

Since: 0.1

Instance details

Defined in Data.Bytes.Size

Methods

rnf :: Size -> () #

Bounded Size Source #

Since: 0.1

Instance details

Defined in Data.Bytes.Size

Enum Size Source #

Since: 0.1

Instance details

Defined in Data.Bytes.Size

Methods

succ :: Size -> Size #

pred :: Size -> Size #

toEnum :: Int -> Size #

fromEnum :: Size -> Int #

enumFrom :: Size -> [Size] #

enumFromThen :: Size -> Size -> [Size] #

enumFromTo :: Size -> Size -> [Size] #

enumFromThenTo :: Size -> Size -> Size -> [Size] #

Generic Size Source # 
Instance details

Defined in Data.Bytes.Size

Associated Types

type Rep Size

Since: si-bytes-0.1

Instance details

Defined in Data.Bytes.Size

type Rep Size = D1 ('MetaData "Size" "Data.Bytes.Size" "si-bytes-0.1-inplace" 'False) (((C1 ('MetaCons "B" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "K" 'PrefixI 'False) (U1 :: Type -> Type)) :+: (C1 ('MetaCons "M" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "G" 'PrefixI 'False) (U1 :: Type -> Type))) :+: ((C1 ('MetaCons "T" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "P" 'PrefixI 'False) (U1 :: Type -> Type)) :+: (C1 ('MetaCons "E" 'PrefixI 'False) (U1 :: Type -> Type) :+: (C1 ('MetaCons "Z" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "Y" 'PrefixI 'False) (U1 :: Type -> Type)))))

Methods

from :: Size -> Rep Size x #

to :: Rep Size x -> Size #

Show Size Source #

Since: 0.1

Instance details

Defined in Data.Bytes.Size

Methods

showsPrec :: Int -> Size -> ShowS #

show :: Size -> String #

showList :: [Size] -> ShowS #

Eq Size Source #

Since: 0.1

Instance details

Defined in Data.Bytes.Size

Methods

(==) :: Size -> Size -> Bool #

(/=) :: Size -> Size -> Bool #

Ord Size Source #

Since: 0.1

Instance details

Defined in Data.Bytes.Size

Methods

compare :: Size -> Size -> Ordering #

(<) :: Size -> Size -> Bool #

(<=) :: Size -> Size -> Bool #

(>) :: Size -> Size -> Bool #

(>=) :: Size -> Size -> Bool #

max :: Size -> Size -> Size #

min :: Size -> Size -> Size #

Hashable Size Source #

Since: 0.1

Instance details

Defined in Data.Bytes.Size

Parser Size Source #

Since: 0.1

Instance details

Defined in Data.Bytes.Size

TestEquality SSize Source #

Since: 0.1

Instance details

Defined in Data.Bytes.Size

Methods

testEquality :: forall (a :: Size) (b :: Size). SSize a -> SSize b -> Maybe (a :~: b) #

type Rep Size Source #

Since: 0.1

Instance details

Defined in Data.Bytes.Size

type Rep Size = D1 ('MetaData "Size" "Data.Bytes.Size" "si-bytes-0.1-inplace" 'False) (((C1 ('MetaCons "B" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "K" 'PrefixI 'False) (U1 :: Type -> Type)) :+: (C1 ('MetaCons "M" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "G" 'PrefixI 'False) (U1 :: Type -> Type))) :+: ((C1 ('MetaCons "T" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "P" 'PrefixI 'False) (U1 :: Type -> Type)) :+: (C1 ('MetaCons "E" 'PrefixI 'False) (U1 :: Type -> Type) :+: (C1 ('MetaCons "Z" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "Y" 'PrefixI 'False) (U1 :: Type -> Type)))))

data SSize (s :: Size) where Source #

Singleton for Size.

Since: 0.1

Constructors

SB :: SSize 'B

Since: 0.1

SK :: SSize 'K

Since: 0.1

SM :: SSize 'M

Since: 0.1

SG :: SSize 'G

Since: 0.1

ST :: SSize 'T

Since: 0.1

SP :: SSize 'P

Since: 0.1

SE :: SSize 'E

Since: 0.1

SZ :: SSize 'Z

Since: 0.1

SY :: SSize 'Y

Since: 0.1

Instances

Instances details
TestEquality SSize Source #

Since: 0.1

Instance details

Defined in Data.Bytes.Size

Methods

testEquality :: forall (a :: Size) (b :: Size). SSize a -> SSize b -> Maybe (a :~: b) #

NFData (SSize s) Source #

Since: 0.1

Instance details

Defined in Data.Bytes.Size

Methods

rnf :: SSize s -> () #

Show (SSize s) Source #

Since: 0.1

Instance details

Defined in Data.Bytes.Size

Methods

showsPrec :: Int -> SSize s -> ShowS #

show :: SSize s -> String #

showList :: [SSize s] -> ShowS #

class SingSize (s :: Size) where Source #

Typeclass for recovering the Size at runtime.

Since: 0.1

Methods

singSize :: SSize s Source #

Since: 0.1

Instances

Instances details
SingSize 'B Source #

Since: 0.1

Instance details

Defined in Data.Bytes.Size

Methods

singSize :: SSize 'B Source #

SingSize 'E Source #

Since: 0.1

Instance details

Defined in Data.Bytes.Size

Methods

singSize :: SSize 'E Source #

SingSize 'G Source #

Since: 0.1

Instance details

Defined in Data.Bytes.Size

Methods

singSize :: SSize 'G Source #

SingSize 'K Source #

Since: 0.1

Instance details

Defined in Data.Bytes.Size

Methods

singSize :: SSize 'K Source #

SingSize 'M Source #

Since: 0.1

Instance details

Defined in Data.Bytes.Size

Methods

singSize :: SSize 'M Source #

SingSize 'P Source #

Since: 0.1

Instance details

Defined in Data.Bytes.Size

Methods

singSize :: SSize 'P Source #

SingSize 'T Source #

Since: 0.1

Instance details

Defined in Data.Bytes.Size

Methods

singSize :: SSize 'T Source #

SingSize 'Y Source #

Since: 0.1

Instance details

Defined in Data.Bytes.Size

Methods

singSize :: SSize 'Y Source #

SingSize 'Z Source #

Since: 0.1

Instance details

Defined in Data.Bytes.Size

Methods

singSize :: SSize 'Z Source #

withSingSize :: forall (s :: Size) r. SSize s -> (SingSize s => r) -> r Source #

Singleton "with"-style convenience function. Allows us to run a computation SingSize d => r without explicitly pattern-matching every time.

Since: 0.1

ssizeToSize :: forall (s :: Size). SSize s -> Size Source #

Since: 0.1

Sized Types

class Sized a where Source #

Types that have a size.

Since: 0.1

Associated Types

type HideSize a Source #

Type used to hide the size.

Since: 0.1

Methods

sizeOf :: a -> Size Source #

Retrieves the size.

Examples

Expand
>>> import Data.Bytes (Bytes (..))
>>> sizeOf (MkBytes @G 7)
G
>>> sizeOf (hideSize $ MkBytes @M 7)
M
>>> import Data.Bytes.Network (NetBytes (..), Direction (..))
>>> sizeOf (hideSize $ MkNetBytesP @Up @M 7)
M

Since: 0.1

hideSize :: a -> HideSize a Source #

Hides the size.

Examples

Expand
>>> import Data.Bytes (Bytes (..))
>>> hideSize (MkBytes @G 7)
MkSomeSize SG (MkBytes 7)

Instances

Instances details
Sized (SomeSize n) Source #

Since: 0.1

Instance details

Defined in Data.Bytes.Internal

Associated Types

type HideSize (SomeSize n) 
Instance details

Defined in Data.Bytes.Internal

Sized (SomeNet n) Source #

Since: 0.1

Instance details

Defined in Data.Bytes.Network.Internal

Associated Types

type HideSize (SomeNet n) 
Instance details

Defined in Data.Bytes.Network.Internal

type HideSize (SomeNet n) = SomeNet n
SingSize s => Sized (Bytes s n) Source #

Since: 0.1

Instance details

Defined in Data.Bytes.Internal

Associated Types

type HideSize (Bytes s n) 
Instance details

Defined in Data.Bytes.Internal

type HideSize (Bytes s n) = SomeSize n

Methods

sizeOf :: Bytes s n -> Size Source #

hideSize :: Bytes s n -> HideSize (Bytes s n) Source #

SingSize s => Sized (SomeNetDir s n) Source #

Since: 0.1

Instance details

Defined in Data.Bytes.Network.Internal

Associated Types

type HideSize (SomeNetDir s n) 
Instance details

Defined in Data.Bytes.Network.Internal

type HideSize (SomeNetDir s n) = SomeNet n
Sized (SomeNetSize d n) Source #

Since: 0.1

Instance details

Defined in Data.Bytes.Network.Internal

Associated Types

type HideSize (SomeNetSize d n) 
Instance details

Defined in Data.Bytes.Network.Internal

SingSize s => Sized (NetBytes d s n) Source #

Since: 0.1

Instance details

Defined in Data.Bytes.Network.Internal

Associated Types

type HideSize (NetBytes d s n) 
Instance details

Defined in Data.Bytes.Network.Internal

type HideSize (NetBytes d s n) = SomeNetSize d n

Methods

sizeOf :: NetBytes d s n -> Size Source #

hideSize :: NetBytes d s n -> HideSize (NetBytes d s n) Source #

Type Families for Relating Tags

type family NextSize (s :: Size) = (t :: Size) where ... Source #

Type family that relates units to the next larger one.

Examples

Expand
>>> :kind! NextSize 'M
NextSize 'M :: Size
= G
>>> :kind! NextSize 'Y
NextSize 'Y :: Size
= (TypeError ...)

Since: 0.1

Equations

NextSize 'B = 'K 
NextSize 'K = 'M 
NextSize 'M = 'G 
NextSize 'G = 'T 
NextSize 'T = 'P 
NextSize 'P = 'E 
NextSize 'E = 'Z 
NextSize 'Z = 'Y 
NextSize 'Y = TypeError ('Text "The byte unit Y does not have a 'next size'.") :: Size 

type family PrevSize (s :: Size) = (t :: Size) where ... Source #

Type family that relates units to the previous smaller one.

Examples

Expand
>>> :kind! PrevSize 'M
PrevSize 'M :: Size
= K
>>> :kind! PrevSize 'B
PrevSize 'B :: Size
= (TypeError ...)

Since: 0.1

Equations

PrevSize 'B = TypeError ('Text "The byte unit B does not have a 'previous size'.") :: Size 
PrevSize 'K = 'B 
PrevSize 'M = 'K 
PrevSize 'G = 'M 
PrevSize 'T = 'G 
PrevSize 'P = 'T 
PrevSize 'E = 'P 
PrevSize 'Z = 'E 
PrevSize 'Y = 'Z 

Optics

_B :: Prism' Size () Source #

Since: 0.1

_K :: Prism' Size () Source #

Since: 0.1

_M :: Prism' Size () Source #

Since: 0.1

_G :: Prism' Size () Source #

Since: 0.1

_T :: Prism' Size () Source #

Since: 0.1

_P :: Prism' Size () Source #

Since: 0.1

_E :: Prism' Size () Source #

Since: 0.1

_Z :: Prism' Size () Source #

Since: 0.1

_Y :: Prism' Size () Source #

Since: 0.1