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

Data.Bytes.Class.Conversion

Description

Provides typeclasses for convert between byte sizes.

Since: 0.1

Synopsis

Documentation

class Conversion a where Source #

This class allows one to transform a bytes type to any Size. For types with existentially quantified Size (e.g. SomeSize, SomeNetSize), this will "undo" the existential quantification.

Since: 0.1

Associated Types

type Converted (t :: Size) a = (r :: Type) | r -> t Source #

Since: 0.1

Methods

convert :: forall (t :: Size). SingSize t => Proxy t -> a -> Converted t a Source #

convert (Proxy :: Proxy t) x converts x to size t.

Examples

Expand
>>> let bytes = MkBytes 50_000 :: Bytes 'M Int
>>> let gBytes = convert @_ @G Proxy bytes
>>> :type gBytes
gBytes :: Bytes G Int
>>> gBytes
MkBytes 50
>>> let bytes = hideSize (MkBytes 0.2 :: Bytes 'T Float)
>>> let mBytes = convert @_ @M Proxy bytes
>>> :type mBytes
mBytes :: Bytes M Float
>>> mBytes
MkBytes 200000.0

Since: 0.1

Instances

Instances details
(FromInteger n, MGroup n) => Conversion (SomeSize n) Source #

Since: 0.1

Instance details

Defined in Data.Bytes.Internal

Methods

convert :: forall (t :: Size). SingSize t => Proxy t -> SomeSize n -> Converted t (SomeSize n) Source #

(FromInteger n, MGroup n) => Conversion (SomeNet n) Source #

Since: 0.1

Instance details

Defined in Data.Bytes.Network.Internal

Methods

convert :: forall (t :: Size). SingSize t => Proxy t -> SomeNet n -> Converted t (SomeNet n) Source #

(FromInteger n, MGroup n, SingSize s) => Conversion (Bytes s n) Source #

Since: 0.1

Instance details

Defined in Data.Bytes.Internal

Methods

convert :: forall (t :: Size). SingSize t => Proxy t -> Bytes s n -> Converted t (Bytes s n) Source #

(FromInteger n, MGroup n, SingSize s) => Conversion (SomeNetDir s n) Source #

Since: 0.1

Instance details

Defined in Data.Bytes.Network.Internal

Methods

convert :: forall (t :: Size). SingSize t => Proxy t -> SomeNetDir s n -> Converted t (SomeNetDir s n) Source #

(FromInteger n, MGroup n) => Conversion (SomeNetSize d n) Source #

Since: 0.1

Instance details

Defined in Data.Bytes.Network.Internal

Methods

convert :: forall (t :: Size). SingSize t => Proxy t -> SomeNetSize d n -> Converted t (SomeNetSize d n) Source #

(FromInteger n, MGroup n, SingSize s) => Conversion (NetBytes d s n) Source #

Since: 0.1

Instance details

Defined in Data.Bytes.Network.Internal

Methods

convert :: forall (t :: Size). SingSize t => Proxy t -> NetBytes d s n -> Converted t (NetBytes d s n) Source #

convert' :: (FromInteger n, MGroup n) => Size -> Size -> n -> n Source #

Low level function for converting a numeric literal between byte sizes. convert b1 b2 converts from b1 to b2, e.g. convert G K = \n -> n * 1_000_000. The higher level byte types and functions should be preferred (e.g. Conversion, Data.Bytes.Class.Normalize), but this is here when it is needed.

Since: 0.1

convertWitness :: forall (s :: Size) n. (FromInteger n, MGroup n, SingSize s) => Size -> n -> n Source #

Low level function for converting a numeric literal from the inferred SingSize to the parameter Size. For instance,

>>> convertWitness @K M 5_000
5

This is slightly more principled than convert, but the higher level byte types and functions should still be preferred (e.g. Bytes, Normalize).

Since: 0.1