Safe Haskell | None |
---|---|
Language | Haskell2010 |
Data.Bytes.Class.Conversion
Contents
Description
Provides typeclasses for convert between byte sizes.
Since: 0.1
Synopsis
- class Conversion a where
- convertSize :: (FromInteger n, MGroup n) => Size -> Size -> n -> n
- convertWitness :: forall (s :: Size) n. (FromInteger n, MGroup n, SingI s) => Size -> n -> n
High-level
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
Methods
convert_ :: forall (t :: Size). SingI t => a -> Converted t a Source #
convert_ @_ @t x
converts x
to size t
.
Examples
>>>
let bytes = MkBytes 50_000 :: Bytes 'M Int
>>>
let gBytes = convert_ @_ @G bytes
>>>
:type gBytes
gBytes :: Bytes G Int>>>
gBytes
MkBytes 50
>>>
let bytes = hideSize (MkBytes 0.2 :: Bytes 'T Float)
>>>
let mBytes = convert_ @_ @M bytes
>>>
:type mBytes
mBytes :: Bytes M Float>>>
mBytes
MkBytes 200000.0
Since: 0.1
Instances
(FromInteger n, MGroup n) => Conversion (SomeSize n) Source # | Since: 0.1 |
(FromInteger n, MGroup n) => Conversion (SomeNet n) Source # | Since: 0.1 |
(FromInteger n, MGroup n, SingI s) => Conversion (Bytes s n) Source # | Since: 0.1 |
(FromInteger n, MGroup n, SingI s) => Conversion (SomeNetDir s n) Source # | Since: 0.1 |
Defined in Data.Bytes.Network.Internal Methods convert_ :: forall (t :: Size). SingI t => SomeNetDir s n -> Converted t (SomeNetDir s n) Source # | |
(FromInteger n, MGroup n) => Conversion (SomeNetSize d n) Source # | Since: 0.1 |
Defined in Data.Bytes.Network.Internal Methods convert_ :: forall (t :: Size). SingI t => SomeNetSize d n -> Converted t (SomeNetSize d n) Source # | |
(FromInteger n, MGroup n, SingI s) => Conversion (NetBytes d s n) Source # | Since: 0.1 |
Low-level
convertSize :: (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, SingI s) => Size -> n -> n Source #
Low level function for converting a numeric literal from the inferred
SingI
to the parameter Size
. For instance,
>>>
convertWitness @K M 5_000
5
This is slightly more principled than convertSize
, but the higher level
byte types and functions should still be preferred
(e.g. Bytes
, Normalize
).
Since: 0.1