Safe Haskell | None |
---|---|
Language | Haskell2010 |
This module serves as an alternative entry point to Data.Bytes, for when tracking uploaded vs. downloaded bytes is necessary. It provides the types and operations for typical usage and is usually the only import required. The core concept is:
- Wrapping a numeric value representing bytes in a new type.
- Attaching phantom labels representing the units (e.g. B, K, M, ...).
- Attaching phantom labels representing the direction (i.e. Down, Up).
This prevents mistakes, such as adding two different byte sizes/directions, or converting between sizes incorrectly.
Since: 0.1
Synopsis
- newtype NetBytes (d :: Direction) (s :: Size) n where
- MkNetBytes (Bytes s n)
- pattern MkNetBytesP :: forall d s n. n -> NetBytes d s n
- data Size
- data Direction
- data SomeNetSize (d :: Direction) n
- class Sized a where
- data SomeNetDir (s :: Size) n
- data SomeNet n
- class Directed a where
- type HideDirection a
- directionOf :: a -> Direction
- hideDirection :: a -> HideDirection a
- class RawNumeric a where
- class Conversion a where
- convert :: forall (t :: Size) -> SingSize t => forall a. Conversion a => a -> Converted t a
- class Normalize a where
- module Numeric.Algebra
- module Numeric.Literal.Integer
- module Numeric.Literal.Rational
- module Data.Bytes.Formatting
- class Parser a
- parse :: Parser a => Text -> Either Text a
- _MkNetBytes :: forall (s :: Size) (d :: Direction) n. Iso' (NetBytes d s n) (Bytes s n)
- _MkSomeNetSize :: forall (s :: Size) (d :: Direction) n. (FromInteger n, MGroup n, SingSize s) => Iso' (SomeNetSize d n) (NetBytes d s n)
- _MkSomeNetDir :: forall (s :: Size) (d :: Direction) n. SingDirection d => Review (SomeNetDir s n) (NetBytes d s n)
- _MkSomeNet :: forall (s :: Size) (d :: Direction) n. (SingDirection d, SingSize s) => Review (SomeNet n) (NetBytes d s n)
- _B :: Prism' Size ()
- _K :: Prism' Size ()
- _M :: Prism' Size ()
- _G :: Prism' Size ()
- _T :: Prism' Size ()
- _P :: Prism' Size ()
- _E :: Prism' Size ()
- _Z :: Prism' Size ()
- _Y :: Prism' Size ()
- _Down :: Prism' Direction ()
- _Up :: Prism' Direction ()
- class Default a where
- def :: a
Introduction
The main idea is to attach phantom labels to the numeric bytes, so we can track the size and direction units. This allows us to safely manipulate byte values without mixing up units, performing incorrect conversions, etc.
The core types are a newtype wrapper NetBytes
, the Size
units, and the
Direction
units:
newtype NetBytes (d :: Direction) (s :: Size) n Source #
Wrapper around the Bytes
type that adds the Direction
tag.
Examples
>>>
MkNetBytesP @Up @M 1000
MkNetBytes (MkBytes 1000)
Since: 0.1
MkNetBytes (Bytes s n) |
pattern MkNetBytesP :: forall d s n. n -> NetBytes d s n | Pattern for de/constructing Since: 0.1 |
Instances
Byte units.
Since: 0.1
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
NFData Size Source # | Since: 0.1 | ||||
Defined in Data.Bytes.Size | |||||
Bounded Size Source # | Since: 0.1 | ||||
Enum Size Source # | Since: 0.1 | ||||
Generic Size Source # | |||||
Defined in Data.Bytes.Size
| |||||
Show Size Source # | Since: 0.1 | ||||
Eq Size Source # | Since: 0.1 | ||||
Ord Size Source # | Since: 0.1 | ||||
Hashable Size Source # | Since: 0.1 | ||||
Parser Size Source # | Since: 0.1 | ||||
TestEquality SSize Source # | Since: 0.1 | ||||
Defined in Data.Bytes.Size | |||||
type Rep Size Source # | Since: 0.1 | ||||
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))))) |
Tags for differentiating downloaded vs. uploaded bytes.
Since: 0.1
Instances
NFData Direction Source # | Since: 0.1 |
Defined in Data.Bytes.Network.Direction | |
Generic Direction Source # | |
Defined in Data.Bytes.Network.Direction | |
Show Direction Source # | Since: 0.1 |
Eq Direction Source # | Since: 0.1 |
Hashable Direction Source # | Since: 0.1 |
Parser Direction Source # | Since: 0.1 |
TestEquality SDirection Source # | Since: 0.1 |
Defined in Data.Bytes.Network.Direction testEquality :: forall (a :: Direction) (b :: Direction). SDirection a -> SDirection b -> Maybe (a :~: b) # | |
type Rep Direction Source # | Since: 0.1 |
Basic Usage
Construction
There are several ways to construct a NetBytes
type.
>>>
afromInteger 80 :: NetBytes Up M Int
MkNetBytes (MkBytes 80)Directly
>>>
import Data.Bytes (Bytes (MkBytes))
>>>
MkNetBytes (MkBytes 80) :: NetBytes Down M Int
MkNetBytes (MkBytes 80)>>>
-- using the @MkNetBytesP :: n -> NetBytes d s n@ pattern synonym
>>>
MkNetBytesP 80 :: NetBytes Up K Int
MkNetBytes (MkBytes 80)Optics (
optics-core
)>>>
-- 1. Using _MkNetBytes to construct a NetBytes from a Bytes
>>>
import Optics.Core (review, (%))
>>>
import Data.Bytes (_MkBytes)
>>>
(review _MkNetBytes (MkBytes 80)) :: NetBytes Up G Int -- Bytes -> NetBytes
MkNetBytes (MkBytes 80)>>>
-- 2. Using _MkNetBytes and _MkBytes to construct a NetBytes from a
>>>
-- numeric value.
>>>
(review (_MkNetBytes % _MkBytes) 70) :: NetBytes Up G Int -- n -> NetBytes
MkNetBytes (MkBytes 70)>>>
-- 3. Using #unNetBytes to construct a NetBytes from a numeric value.
>>>
(review #unNetBytes 70) :: NetBytes Up G Int -- n -> NetBytes
MkNetBytes (MkBytes 70)
Unknown Size
We sometimes have to deal with unknown sizes at runtime, which presents
a problem. We handle this with the
type, which existentially
quantifies the SomeNetSize
Size
:
data SomeNetSize (d :: Direction) n Source #
Wrapper for NetBytes
, existentially quantifying the size. This is useful
when a function does not know a priori what size it should return e.g.
>>>
:{
getUpTraffic :: IO (SomeNetSize Up Float) getUpTraffic = do -- getUpTrafficRaw :: IO (Float, String) (bytes, units) <- getUpTrafficRaw pure $ case units of "B" -> hideSize $ MkNetBytesP @Up @B bytes "K" -> hideSize $ MkNetBytesP @Up @K bytes _ -> error "todo" :}
We define an equivalence relation on SomeNetSize
that takes units into
account. For instance,
>>>
hideSize (MkNetBytesP @Up @K 1000) == hideSize (MkNetBytesP @Up @M 1)
True
Because we expose the underlying NetBytes
in several ways (e.g. Show
,
the SSize
witness), this is technically unlawful for equality
as it breaks the extensionality law:
\[ x = y \implies f(x) = f(y). \]
Since: 0.1
Instances
HasField "unSomeNetSize" (SomeNetSize d n) n Source # | Since: 0.1 | ||||
Defined in Data.Bytes.Network.Internal getField :: SomeNetSize d n -> n # | |||||
(k ~ A_Getter, a ~ n, b ~ n) => LabelOptic "unSomeNetSize" k (SomeNetSize d n) (SomeNetSize d n) a b Source # | Since: 0.1 | ||||
Defined in Data.Bytes.Network.Internal labelOptic :: Optic k NoIx (SomeNetSize d n) (SomeNetSize d n) a b Source # | |||||
Functor (SomeNetSize d) Source # | Since: 0.1 | ||||
Defined in Data.Bytes.Network.Internal fmap :: (a -> b) -> SomeNetSize d a -> SomeNetSize d b # (<$) :: a -> SomeNetSize d b -> SomeNetSize d a # | |||||
Foldable (SomeNetSize d) Source # | Since: 0.1 | ||||
Defined in Data.Bytes.Network.Internal fold :: Monoid m => SomeNetSize d m -> m # foldMap :: Monoid m => (a -> m) -> SomeNetSize d a -> m # foldMap' :: Monoid m => (a -> m) -> SomeNetSize d a -> m # foldr :: (a -> b -> b) -> b -> SomeNetSize d a -> b # foldr' :: (a -> b -> b) -> b -> SomeNetSize d a -> b # foldl :: (b -> a -> b) -> b -> SomeNetSize d a -> b # foldl' :: (b -> a -> b) -> b -> SomeNetSize d a -> b # foldr1 :: (a -> a -> a) -> SomeNetSize d a -> a # foldl1 :: (a -> a -> a) -> SomeNetSize d a -> a # toList :: SomeNetSize d a -> [a] # null :: SomeNetSize d a -> Bool # length :: SomeNetSize d a -> Int # elem :: Eq a => a -> SomeNetSize d a -> Bool # maximum :: Ord a => SomeNetSize d a -> a # minimum :: Ord a => SomeNetSize d a -> a # sum :: Num a => SomeNetSize d a -> a # product :: Num a => SomeNetSize d a -> a # | |||||
Traversable (SomeNetSize d) Source # | Since: 0.1 | ||||
Defined in Data.Bytes.Network.Internal traverse :: Applicative f => (a -> f b) -> SomeNetSize d a -> f (SomeNetSize d b) # sequenceA :: Applicative f => SomeNetSize d (f a) -> f (SomeNetSize d a) # mapM :: Monad m => (a -> m b) -> SomeNetSize d a -> m (SomeNetSize d b) # sequence :: Monad m => SomeNetSize d (m a) -> m (SomeNetSize d a) # | |||||
(Field n, FromInteger n) => AGroup (SomeNetSize d n) Source # | Since: 0.1 | ||||
Defined in Data.Bytes.Network.Internal (.-.) :: SomeNetSize d n -> SomeNetSize d n -> SomeNetSize d n Source # | |||||
(FromInteger n, Semifield n) => AMonoid (SomeNetSize d n) Source # | Since: 0.1 | ||||
Defined in Data.Bytes.Network.Internal zero :: SomeNetSize d n Source # | |||||
(ASemigroup n, FromInteger n, MGroup n) => ASemigroup (SomeNetSize d n) Source # | Since: 0.1 | ||||
Defined in Data.Bytes.Network.Internal (.+.) :: SomeNetSize d n -> SomeNetSize d n -> SomeNetSize d n Source # | |||||
FromInteger n => FromInteger (SomeNetSize d n) Source # | Fixed size Since: 0.1 | ||||
Defined in Data.Bytes.Network.Internal afromInteger :: Integer -> SomeNetSize d n Source # | |||||
FromRational n => FromRational (SomeNetSize d n) Source # | Fixed size Since: 0.1 | ||||
Defined in Data.Bytes.Network.Internal afromRational :: Rational -> SomeNetSize d n Source # | |||||
NFData n => NFData (SomeNetSize d n) Source # | Since: 0.1 | ||||
Defined in Data.Bytes.Network.Internal rnf :: SomeNetSize d n -> () # | |||||
Show n => Show (SomeNetSize d n) Source # | Since: 0.1 | ||||
Defined in Data.Bytes.Network.Internal showsPrec :: Int -> SomeNetSize d n -> ShowS # show :: SomeNetSize d n -> String # showList :: [SomeNetSize d n] -> ShowS # | |||||
(Eq n, FromInteger n, MGroup n) => Eq (SomeNetSize d n) Source # | Since: 0.1 | ||||
Defined in Data.Bytes.Network.Internal (==) :: SomeNetSize d n -> SomeNetSize d n -> Bool # (/=) :: SomeNetSize d n -> SomeNetSize d n -> Bool # | |||||
(FromInteger n, MGroup n, Ord n) => Ord (SomeNetSize d n) Source # | Since: 0.1 | ||||
Defined in Data.Bytes.Network.Internal compare :: SomeNetSize d n -> SomeNetSize d n -> Ordering # (<) :: SomeNetSize d n -> SomeNetSize d n -> Bool # (<=) :: SomeNetSize d n -> SomeNetSize d n -> Bool # (>) :: SomeNetSize d n -> SomeNetSize d n -> Bool # (>=) :: SomeNetSize d n -> SomeNetSize d n -> Bool # max :: SomeNetSize d n -> SomeNetSize d n -> SomeNetSize d n # min :: SomeNetSize d n -> SomeNetSize d n -> SomeNetSize d n # | |||||
(FromInteger n, Hashable n, MGroup n) => Hashable (SomeNetSize d n) Source # | Since: 0.1 | ||||
Defined in Data.Bytes.Network.Internal hashWithSalt :: Int -> SomeNetSize d n -> Int Source # hash :: SomeNetSize d n -> Int Source # | |||||
(FromInteger n, MGroup n) => Conversion (SomeNetSize d n) Source # | Since: 0.1 | ||||
Defined in Data.Bytes.Network.Internal convert_ :: forall (t :: Size). SingSize t => SomeNetSize d n -> Converted t (SomeNetSize d n) Source # | |||||
(FromInteger n, MGroup n, Normed n, Ord n) => Normalize (SomeNetSize d n) Source # | Since: 0.1 | ||||
Defined in Data.Bytes.Network.Internal
normalize :: SomeNetSize d n -> Norm (SomeNetSize d n) Source # | |||||
Read n => Parser (SomeNetSize d n) Source # | Since: 0.1 | ||||
Defined in Data.Bytes.Network.Internal | |||||
RawNumeric (SomeNetSize d n) Source # | Since: 0.1 | ||||
Defined in Data.Bytes.Network.Internal
toRaw :: SomeNetSize d n -> Raw (SomeNetSize d n) Source # | |||||
SingDirection d => Directed (SomeNetSize d n) Source # | Since: 0.1 | ||||
Defined in Data.Bytes.Network.Internal
directionOf :: SomeNetSize d n -> Direction Source # hideDirection :: SomeNetSize d n -> HideDirection (SomeNetSize d n) Source # | |||||
Sized (SomeNetSize d n) Source # | Since: 0.1 | ||||
Defined in Data.Bytes.Network.Internal
sizeOf :: SomeNetSize d n -> Size Source # hideSize :: SomeNetSize d n -> HideSize (SomeNetSize d n) Source # | |||||
MGroup n => MSemiSpace (SomeNetSize d n) n Source # | Since: 0.1 | ||||
Defined in Data.Bytes.Network.Internal (.*) :: SomeNetSize d n -> n -> SomeNetSize d n Source # | |||||
MGroup n => MSpace (SomeNetSize d n) n Source # | Since: 0.1 | ||||
Defined in Data.Bytes.Network.Internal (.%) :: SomeNetSize d n -> n -> SomeNetSize d n Source # | |||||
(Field n, FromInteger n) => Module (SomeNetSize d n) n Source # | Since: 0.1 | ||||
Defined in Data.Bytes.Network.Internal | |||||
(FromInteger n, Semifield n) => Semimodule (SomeNetSize d n) n Source # | Since: 0.1 | ||||
Defined in Data.Bytes.Network.Internal | |||||
(FromInteger n, Semifield n) => SemivectorSpace (SomeNetSize d n) n Source # | Since: 0.1 | ||||
Defined in Data.Bytes.Network.Internal | |||||
(FromInteger n, Field n) => VectorSpace (SomeNetSize d n) n Source # | Since: 0.1 | ||||
Defined in Data.Bytes.Network.Internal | |||||
type Converted t (SomeNetSize d n) Source # | |||||
Defined in Data.Bytes.Network.Internal | |||||
type Norm (SomeNetSize d n) Source # | |||||
Defined in Data.Bytes.Network.Internal | |||||
type Raw (SomeNetSize d n) Source # | |||||
Defined in Data.Bytes.Network.Internal | |||||
type HideDirection (SomeNetSize d n) Source # | |||||
Defined in Data.Bytes.Network.Internal | |||||
type HideSize (SomeNetSize d n) Source # | |||||
Defined in Data.Bytes.Network.Internal |
Sized
Fortunately, we do not have to directly use the constructor or singletons.
We can instead use the Sized
class.
Types that have a size.
Since: 0.1
Retrieves the size.
Examples
>>>
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
>>>
import Data.Bytes (Bytes (..))
>>>
hideSize (MkBytes @G 7)
MkSomeSize SG (MkBytes 7)
Instances
Sized (SomeSize n) Source # | Since: 0.1 | ||||
Sized (SomeNet n) Source # | Since: 0.1 | ||||
SingSize s => Sized (Bytes s n) Source # | Since: 0.1 | ||||
SingSize s => Sized (SomeNetDir s n) Source # | Since: 0.1 | ||||
Defined in Data.Bytes.Network.Internal
sizeOf :: SomeNetDir s n -> Size Source # hideSize :: SomeNetDir s n -> HideSize (SomeNetDir s n) Source # | |||||
Sized (SomeNetSize d n) Source # | Since: 0.1 | ||||
Defined in Data.Bytes.Network.Internal
sizeOf :: SomeNetSize d n -> Size Source # hideSize :: SomeNetSize d n -> HideSize (SomeNetSize d n) Source # | |||||
SingSize s => Sized (NetBytes d s n) Source # | Since: 0.1 | ||||
Optics
Once again, we can use optics for this.
>>>
import Optics.Core (review)
>>>
review _MkSomeNetSize (MkNetBytesP 70 :: NetBytes Down G Int)
MkSomeNetSize SG (MkNetBytes (MkBytes 70))
Unknown Direction
Like sizes, we can also handle unknown directions at runtime. The types
involved here are SomeNetDir
(hiding direction only) and SomeNet
(hiding both direction and size).
data SomeNetDir (s :: Size) n Source #
Wrapper for NetBytes
, existentially quantifying the direction.
This is useful when a function does not know a priori what
direction it should return e.g.
>>>
:{
getMaxTraffic :: IO (SomeNetDir K Double) getMaxTraffic = do -- getMaxTraffickRaw :: IO (Double, String) (bytes, direction) <- getMaxTraffickRaw pure $ case direction of "down" -> hideDirection $ MkNetBytesP @Down bytes "up" -> hideDirection $ MkNetBytesP @Up bytes _ -> error "bad direction" :}
We deliberately do not provide instances for SomeX classes that could be
used to combine arbitrary SomeNetDir
s (e.g. Applicative
,
AGroup
), as that would defeat the purpose
of enforcing the distinction between upload and downloaded bytes.
Equality is determined by the usual equivalence class -- that takes units into account -- and by considering the direction.
>>>
let x = MkNetBytesP @Up @K 1000 :: NetBytes Up K Int
>>>
let y = MkNetBytesP @Down @K 1000 :: NetBytes Down K Int
>>>
hideDirection x == hideDirection x
True>>>
hideDirection x == hideDirection y
False
Notice no Ord
instance is provided, as we provide no ordering for
Direction
.
Since: 0.1
Instances
HasField "unSomeNetDir" (SomeNetDir s n) n Source # | Since: 0.1 | ||||
Defined in Data.Bytes.Network.Internal getField :: SomeNetDir s n -> n # | |||||
(k ~ A_Getter, a ~ n, b ~ n) => LabelOptic "unSomeNetDir" k (SomeNetDir s n) (SomeNetDir s n) a b Source # | Since: 0.1 | ||||
Defined in Data.Bytes.Network.Internal labelOptic :: Optic k NoIx (SomeNetDir s n) (SomeNetDir s n) a b Source # | |||||
Functor (SomeNetDir s) Source # | Since: 0.1 | ||||
Defined in Data.Bytes.Network.Internal fmap :: (a -> b) -> SomeNetDir s a -> SomeNetDir s b # (<$) :: a -> SomeNetDir s b -> SomeNetDir s a # | |||||
Foldable (SomeNetDir s) Source # | Since: 0.1 | ||||
Defined in Data.Bytes.Network.Internal fold :: Monoid m => SomeNetDir s m -> m # foldMap :: Monoid m => (a -> m) -> SomeNetDir s a -> m # foldMap' :: Monoid m => (a -> m) -> SomeNetDir s a -> m # foldr :: (a -> b -> b) -> b -> SomeNetDir s a -> b # foldr' :: (a -> b -> b) -> b -> SomeNetDir s a -> b # foldl :: (b -> a -> b) -> b -> SomeNetDir s a -> b # foldl' :: (b -> a -> b) -> b -> SomeNetDir s a -> b # foldr1 :: (a -> a -> a) -> SomeNetDir s a -> a # foldl1 :: (a -> a -> a) -> SomeNetDir s a -> a # toList :: SomeNetDir s a -> [a] # null :: SomeNetDir s a -> Bool # length :: SomeNetDir s a -> Int # elem :: Eq a => a -> SomeNetDir s a -> Bool # maximum :: Ord a => SomeNetDir s a -> a # minimum :: Ord a => SomeNetDir s a -> a # sum :: Num a => SomeNetDir s a -> a # product :: Num a => SomeNetDir s a -> a # | |||||
Traversable (SomeNetDir d) Source # | Since: 0.1 | ||||
Defined in Data.Bytes.Network.Internal traverse :: Applicative f => (a -> f b) -> SomeNetDir d a -> f (SomeNetDir d b) # sequenceA :: Applicative f => SomeNetDir d (f a) -> f (SomeNetDir d a) # mapM :: Monad m => (a -> m b) -> SomeNetDir d a -> m (SomeNetDir d b) # sequence :: Monad m => SomeNetDir d (m a) -> m (SomeNetDir d a) # | |||||
Normed n => Normed (SomeNetDir s n) Source # | Since: 0.1 | ||||
Defined in Data.Bytes.Network.Internal norm :: SomeNetDir s n -> SomeNetDir s n Source # | |||||
NFData n => NFData (SomeNetDir s n) Source # | Since: 0.1 | ||||
Defined in Data.Bytes.Network.Internal rnf :: SomeNetDir s n -> () # | |||||
Show n => Show (SomeNetDir s n) Source # | Since: 0.1 | ||||
Defined in Data.Bytes.Network.Internal showsPrec :: Int -> SomeNetDir s n -> ShowS # show :: SomeNetDir s n -> String # showList :: [SomeNetDir s n] -> ShowS # | |||||
(Eq n, FromInteger n, SingSize s) => Eq (SomeNetDir s n) Source # | Since: 0.1 | ||||
Defined in Data.Bytes.Network.Internal (==) :: SomeNetDir s n -> SomeNetDir s n -> Bool # (/=) :: SomeNetDir s n -> SomeNetDir s n -> Bool # | |||||
(FromInteger n, Hashable n, MGroup n, SingSize s) => Hashable (SomeNetDir s n) Source # | Since: 0.1 | ||||
Defined in Data.Bytes.Network.Internal hashWithSalt :: Int -> SomeNetDir s n -> Int Source # hash :: SomeNetDir s n -> Int Source # | |||||
(FromInteger n, MGroup n, SingSize s) => Conversion (SomeNetDir s n) Source # | Since: 0.1 | ||||
Defined in Data.Bytes.Network.Internal convert_ :: forall (t :: Size). SingSize t => SomeNetDir s n -> Converted t (SomeNetDir s n) Source # | |||||
(FromInteger n, MGroup n, Normed n, Ord n, SingSize s) => Normalize (SomeNetDir s n) Source # | Since: 0.1 | ||||
Defined in Data.Bytes.Network.Internal
normalize :: SomeNetDir s n -> Norm (SomeNetDir s n) Source # | |||||
Read n => Parser (SomeNetDir s n) Source # | Since: 0.1 | ||||
Defined in Data.Bytes.Network.Internal | |||||
RawNumeric (SomeNetDir s n) Source # | Since: 0.1 | ||||
Defined in Data.Bytes.Network.Internal
toRaw :: SomeNetDir s n -> Raw (SomeNetDir s n) Source # | |||||
Directed (SomeNetDir s n) Source # | Since: 0.1 | ||||
Defined in Data.Bytes.Network.Internal
directionOf :: SomeNetDir s n -> Direction Source # hideDirection :: SomeNetDir s n -> HideDirection (SomeNetDir s n) Source # | |||||
SingSize s => Sized (SomeNetDir s n) Source # | Since: 0.1 | ||||
Defined in Data.Bytes.Network.Internal
sizeOf :: SomeNetDir s n -> Size Source # hideSize :: SomeNetDir s n -> HideSize (SomeNetDir s n) Source # | |||||
MSemigroup n => MSemiSpace (SomeNetDir s n) n Source # | Since: 0.1 | ||||
Defined in Data.Bytes.Network.Internal (.*) :: SomeNetDir s n -> n -> SomeNetDir s n Source # | |||||
MGroup n => MSpace (SomeNetDir s n) n Source # | Since: 0.1 | ||||
Defined in Data.Bytes.Network.Internal (.%) :: SomeNetDir s n -> n -> SomeNetDir s n Source # | |||||
type Converted t (SomeNetDir s n) Source # | |||||
Defined in Data.Bytes.Network.Internal | |||||
type Norm (SomeNetDir s n) Source # | |||||
Defined in Data.Bytes.Network.Internal | |||||
type Raw (SomeNetDir s n) Source # | |||||
Defined in Data.Bytes.Network.Internal | |||||
type HideDirection (SomeNetDir s n) Source # | |||||
Defined in Data.Bytes.Network.Internal | |||||
type HideSize (SomeNetDir s n) Source # | |||||
Defined in Data.Bytes.Network.Internal |
Wrapper for NetBytes
, existentially quantifying the size and
direction. This is useful when a function does not know a priori what
size or direction it should return e.g.
>>>
:{
getMaxTraffic :: IO (SomeNet Double) getMaxTraffic = do -- getMaxTrafficNetRaw :: IO (Double, String, String) (bytes, direction, size) <- getMaxTrafficNetRaw pure $ case (direction, size) of ("Down", "K") -> hideDirection $ hideSize $ MkNetBytesP @Down @K bytes ("Up", "M") -> hideDirection $ hideSize $ MkNetBytesP @Up @M bytes _ -> error "todo" :}
SomeNet
carries along SDirection
and SSize
runtime witnesses
for recovering the Direction
and Size
, respectively.
This instance uses the same equivalence relation from SomeNetSize
w.r.t the size, and also includes an equality check on the direction.
Thus we have, for instance,
>>>
let x = MkNetBytesP 1_000 :: NetBytes Up K Int
>>>
let y = MkNetBytesP 1 :: NetBytes Up M Int
>>>
let z = MkNetBytesP 1_000 :: NetBytes Down K Int
>>>
hideDirection (hideSize x) == hideDirection (hideSize y)
True
>>>
hideDirection (hideSize x) == hideDirection (hideSize z)
False
Since: 0.1
Instances
Functor SomeNet Source # | Since: 0.1 | ||||
Foldable SomeNet Source # | Since: 0.1 | ||||
Defined in Data.Bytes.Network.Internal fold :: Monoid m => SomeNet m -> m # foldMap :: Monoid m => (a -> m) -> SomeNet a -> m # foldMap' :: Monoid m => (a -> m) -> SomeNet a -> m # foldr :: (a -> b -> b) -> b -> SomeNet a -> b # foldr' :: (a -> b -> b) -> b -> SomeNet a -> b # foldl :: (b -> a -> b) -> b -> SomeNet a -> b # foldl' :: (b -> a -> b) -> b -> SomeNet a -> b # foldr1 :: (a -> a -> a) -> SomeNet a -> a # foldl1 :: (a -> a -> a) -> SomeNet a -> a # elem :: Eq a => a -> SomeNet a -> Bool # maximum :: Ord a => SomeNet a -> a # minimum :: Ord a => SomeNet a -> a # | |||||
Traversable SomeNet Source # | Since: 0.1 | ||||
HasField "unSomeNet" (SomeNet n) n Source # | Since: 0.1 | ||||
Defined in Data.Bytes.Network.Internal | |||||
(k ~ A_Getter, a ~ n, b ~ n) => LabelOptic "unSomeNet" k (SomeNet n) (SomeNet n) a b Source # | Since: 0.1 | ||||
Defined in Data.Bytes.Network.Internal | |||||
Normed n => Normed (SomeNet n) Source # | Since: 0.1 | ||||
NFData n => NFData (SomeNet n) Source # | Since: 0.1 | ||||
Defined in Data.Bytes.Network.Internal | |||||
Show n => Show (SomeNet n) Source # | Since: 0.1 | ||||
(Eq n, FromInteger n, MGroup n) => Eq (SomeNet n) Source # | Since: 0.1 | ||||
(FromInteger n, Hashable n, MGroup n) => Hashable (SomeNet n) Source # | Since: 0.1 | ||||
(FromInteger n, MGroup n) => Conversion (SomeNet n) Source # | Since: 0.1 | ||||
(FromInteger n, MGroup n, Normed n, Ord n) => Normalize (SomeNet n) Source # | Since: 0.1 | ||||
Read n => Parser (SomeNet n) Source # | Since: 0.1 | ||||
RawNumeric (SomeNet n) Source # | Since: 0.1 | ||||
Directed (SomeNet n) Source # | Since: 0.1 | ||||
Defined in Data.Bytes.Network.Internal
directionOf :: SomeNet n -> Direction Source # hideDirection :: SomeNet n -> HideDirection (SomeNet n) Source # | |||||
Sized (SomeNet n) Source # | Since: 0.1 | ||||
MSemigroup n => MSemiSpace (SomeNet n) n Source # | Since: 0.1 | ||||
MGroup n => MSpace (SomeNet n) n Source # | Since: 0.1 | ||||
type Converted t (SomeNet n) Source # | |||||
Defined in Data.Bytes.Network.Internal | |||||
type Norm (SomeNet n) Source # | |||||
Defined in Data.Bytes.Network.Internal | |||||
type Raw (SomeNet n) Source # | |||||
Defined in Data.Bytes.Network.Internal | |||||
type HideDirection (SomeNet n) Source # | |||||
Defined in Data.Bytes.Network.Internal | |||||
type HideSize (SomeNet n) Source # | |||||
Defined in Data.Bytes.Network.Internal |
class Directed a where Source #
Types that have a direction.
Since: 0.1
type HideDirection a Source #
Type used to hide the size.
Since: 0.1
directionOf :: a -> Direction Source #
Retrieve the direction.
Examples
>>>
import Data.Bytes.Network
>>>
directionOf (MkNetBytesP @Up @G 7)
Up
>>>
directionOf (hideSize $ hideDirection $ MkNetBytesP @Down @M 100)
Down
Since: 0.1
hideDirection :: a -> HideDirection a Source #
Hides the direction.
Examples
>>>
import Data.Bytes.Network (NetBytes (..), Size (..))
>>>
hideDirection (MkNetBytesP @Up @G 7)
MkSomeNetDir SUp (MkNetBytes (MkBytes 7))
Since: 0.1
Instances
Directed (SomeNet n) Source # | Since: 0.1 | ||||
Defined in Data.Bytes.Network.Internal
directionOf :: SomeNet n -> Direction Source # hideDirection :: SomeNet n -> HideDirection (SomeNet n) Source # | |||||
Directed (SomeNetDir s n) Source # | Since: 0.1 | ||||
Defined in Data.Bytes.Network.Internal
directionOf :: SomeNetDir s n -> Direction Source # hideDirection :: SomeNetDir s n -> HideDirection (SomeNetDir s n) Source # | |||||
SingDirection d => Directed (SomeNetSize d n) Source # | Since: 0.1 | ||||
Defined in Data.Bytes.Network.Internal
directionOf :: SomeNetSize d n -> Direction Source # hideDirection :: SomeNetSize d n -> HideDirection (SomeNetSize d n) Source # | |||||
SingDirection d => Directed (NetBytes d s n) Source # | Since: 0.1 | ||||
Defined in Data.Bytes.Network.Internal
directionOf :: NetBytes d s n -> Direction Source # hideDirection :: NetBytes d s n -> HideDirection (NetBytes d s n) Source # |
Once again, we can use optics for this.
>>>
import Optics.Core (review)
>>>
let x = MkNetBytesP 70 :: NetBytes Down G Int
>>>
review _MkSomeNetDir x
MkSomeNetDir SDown (MkNetBytes (MkBytes 70))
>>>
review _MkSomeNet x
MkSomeNet SDown SG (MkNetBytes (MkBytes 70))
Elimination
RawNumeric
We provide the RawNumeric
class for conveniently unwrapping a type
to the underlying numeric value.
class RawNumeric a where Source #
Abstracts "wrapper" types for generically retrieving a raw numeric value.
Since: 0.1
Retrieves the underlying value.
Examples
>>>
import Data.Bytes (Bytes (..), Size (..), Sized (..))
>>>
toRaw (MkBytes @G 7)
7
>>>
toRaw (hideSize $ MkBytes @M 400)
400
>>>
import Data.Bytes.Network (Direction (..), NetBytes (..))
>>>
toRaw (MkNetBytesP @Up @G 7)
7
>>>
toRaw (hideSize $ MkNetBytesP @Up @G 7)
7
Since: 0.1
Instances
RawNumeric (SomeSize n) Source # | Since: 0.1 | ||||
RawNumeric (SomeNet n) Source # | Since: 0.1 | ||||
RawNumeric (Bytes s n) Source # | Since: 0.1 | ||||
RawNumeric (SomeNetDir s n) Source # | Since: 0.1 | ||||
Defined in Data.Bytes.Network.Internal
toRaw :: SomeNetDir s n -> Raw (SomeNetDir s n) Source # | |||||
RawNumeric (SomeNetSize d n) Source # | Since: 0.1 | ||||
Defined in Data.Bytes.Network.Internal
toRaw :: SomeNetSize d n -> Raw (SomeNetSize d n) Source # | |||||
RawNumeric (NetBytes d s n) Source # | Since: 0.1 | ||||
HasField
We can use HasField
for this too.
>>>
-- {-# LANGUAGE OverloadedRecordDot #-}
>>>
let x1 = MkNetBytesP 7 :: NetBytes Up G Int
>>>
x1.unNetBytes
7
>>>
let x2 = hideSize x1 :: SomeNetSize Up Int
>>>
x2.unSomeNetSize
7
>>>
let x3 = (hideDirection x1) :: SomeNetDir G Int
>>>
x3.unSomeNetDir
7
>>>
let x4 = (hideDirection x2) :: SomeNet Int
>>>
x4.unSomeNet
7
Optics
Optics are another option. The underscore-prefixed optics unwrap one level at a time, since we can freely compose them.
>>>
import Optics.Core (view, (%))
>>>
import Data.Bytes (_MkBytes)
>>>
let x1 = MkNetBytesP 7 :: NetBytes Up G Int
>>>
view (_MkNetBytes % _MkBytes) x1
7
>>>
-- notice we have to convert the numeric value since the requested
>>>
-- return type ('M') differs from the original ('G')
>>>
let x2 = hideSize x1 :: SomeNetSize Up Int
>>>
(view _MkSomeNetSize x2) :: NetBytes Up M Int
MkNetBytes (MkBytes 7000)
>>>
view (_MkSomeNetSize % (_MkNetBytes @M) % _MkBytes) x2
7000
The -XOverloadedLabel
instances unwrap all the way to the underlying numeric
value.
>>>
view #unNetBytes x1
7
>>>
view #unSomeNetSize x2
7
>>>
let x3 = hideDirection x1 :: SomeNetDir G Int
>>>
view #unSomeNetDir x3
7
>>>
let x4 = hideSize x3 :: SomeNet Int
>>>
view #unSomeNet x4
7
Transformations
Converting Units
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
convert_ :: forall (t :: Size). SingSize 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, SingSize s) => Conversion (Bytes s n) Source # | Since: 0.1 |
(FromInteger n, MGroup n, SingSize s) => Conversion (SomeNetDir s n) Source # | Since: 0.1 |
Defined in Data.Bytes.Network.Internal convert_ :: forall (t :: Size). SingSize 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 convert_ :: forall (t :: Size). SingSize 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 |
convert :: forall (t :: Size) -> SingSize t => forall a. Conversion a => a -> Converted t a Source #
Alternative to convert_
with -XTypeApplications, using
-XRequiredTypeArguments.
Examples
>>>
let bytes = MkBytes 50_000 :: Bytes 'M Int
>>>
let gBytes = convert G bytes
>>>
:type gBytes
gBytes :: Bytes G Int>>>
gBytes
MkBytes 50
Since: 0.1
Normalization
class Normalize a where Source #
Used for normalizing bytes b
such that
\[ 1 \le \text{normalize}(b) < 1000 \iff 1\text{ B} \le b < 1000\text{ Y}. \]
In the strictest sense, \(\textrm{normalize} : \mathcal{C} \rightarrow \mathcal{C}\) is not a homomorphism, as the combination of two normalized values may itself not be normalized.
However, because the normalized units varies with the value, normalize
always returns a type that existentially quantifies the size
(e.g. SomeSize
). Eq
for these types is defined in
terms of an equivalence class that takes units into account e.g.
1 P = 1,000 T = 1,000,000 G ...
. Viewed this way, normalize
is actually
an isomorphism, as it is essentially a no-op, never leaving the
equivalence class.
This means we can happily mix normalization with different functions without worrying about the order. The only requirement we have is that such functions respect substitution:
\[ x = y \implies f(x) = f(y). \]
This is certainly true for all the usual mathematical operations we would
normally use, e.g., AGroup
addition,
Module
scalar multiplication. On
the other hand, any functions that inspect the underlying numeric value or
Bytes types could easily break this law. As such they should be treated
with suspicion, at least when used in conjunction with normalize
.
The other consideration we must keep in mind is that the final result of a
series of computations may not be normalized. If this is desired, then
normalize
should be the last operation performed. Using normalize
in
the middle would not cause any harm (other than, perhaps, impacting
efficiency), but it would not guarantee the final result is normalized.
Since: 0.1
normalize :: a -> Norm a Source #
Normalizes the value.
Examples
>>>
let bytes = MkBytes 5000 :: Bytes 'M Int
>>>
normalize bytes
MkSomeSize SG (MkBytes 5)
>>>
let bytes = hideSize (MkBytes 0.01 :: Bytes 'T Float)
>>>
normalize bytes
MkSomeSize SG (MkBytes 10.0)
Since: 0.1
Instances
(FromInteger n, MGroup n, Normed n, Ord n) => Normalize (SomeSize n) Source # | Since: 0.1 | ||||
(FromInteger n, MGroup n, Normed n, Ord n) => Normalize (SomeNet n) Source # | Since: 0.1 | ||||
(FromInteger n, MGroup n, Normed n, Ord n, SingSize s) => Normalize (Bytes s n) Source # | Since: 0.1 | ||||
(FromInteger n, MGroup n, Normed n, Ord n, SingSize s) => Normalize (SomeNetDir s n) Source # | Since: 0.1 | ||||
Defined in Data.Bytes.Network.Internal
normalize :: SomeNetDir s n -> Norm (SomeNetDir s n) Source # | |||||
(FromInteger n, MGroup n, Normed n, Ord n) => Normalize (SomeNetSize d n) Source # | Since: 0.1 | ||||
Defined in Data.Bytes.Network.Internal
normalize :: SomeNetSize d n -> Norm (SomeNetSize d n) Source # | |||||
(FromInteger n, MGroup n, Normed n, Ord n, SingSize s) => Normalize (NetBytes d s n) Source # | Since: 0.1 | ||||
Defined in Data.Bytes.Network.Internal
|
Algebra
The built-in Num
class is abandoned in favor of
algebra-simple's
algebraic hierarchy based on abstract algebra. This is motivated by a
desire to:
- Provide a consistent API.
- Avoid
Num
's infelicities (e.g. nonsense multiplication, dangerousfromInteger
).
NetBytes
and SomeNetSize
are both
AGroup
s. A Ring
instance is not provided because multiplication is nonsensical:
\[ x \;\textrm{mb} \times y \;\textrm{mb} = xy \;\textrm{mb}^2. \]
Fortunately, multiplying bytes by some kind of scalar is both useful and
has an easy interpretation: NetBytes
forms a
Module
over a Ring
(resp. VectorSpace
over a
Field
). This allows us to multiply a NetBytes
or
SomeNetSize
by a scalar in a manner consistent with the above API.
Examples
Addition/Subtraction
>>>
import Numeric.Algebra (ASemigroup ((.+.)), AGroup ((.-.)))
>>>
let mb1 = MkNetBytesP 20 :: NetBytes 'Down 'M Int
>>>
let mb2 = MkNetBytesP 50 :: NetBytes 'Down 'M Int
>>>
mb1 .+. mb2
MkNetBytes (MkBytes 70)>>>
mb1 .-. mb2
MkNetBytes (MkBytes (-30))
>>>
let kb = MkNetBytesP 50 :: NetBytes 'Down 'K Int
>>>
-- mb1 .+. kb -- This would be a type error
>>>
let mbUp = MkNetBytesP 50 :: NetBytes 'Up 'M Int
>>>
-- mb1 .+. mbUp -- This would be a type error
Multiplication
>>>
import Numeric.Algebra (MSemiSpace ((.*)))
>>>
mb1 .* 10
MkNetBytes (MkBytes 200)
Division
>>>
import Numeric.Algebra (MSpace ((.%)))
>>>
mb1 .% 10
MkNetBytes (MkBytes 2)
One may wonder how the AGroup
instance
for SomeNetSize
could possibly work. It is possible (indeed, expected)
that we could have two SomeNetSize
s that have different underlying
NetBytes
types. To handle this, the SomeNetSize
instance will convert
both NetBytes
to a NetBytes
'B
before adding/subtracting.
>>>
let some1 = hideSize (MkNetBytesP 1000 :: NetBytes 'Down 'G Double)
>>>
let some2 = hideSize (MkNetBytesP 500_000 :: NetBytes 'Down 'M Double)
>>>
some1 .+. some2
MkSomeNetSize SB (MkNetBytes (MkBytes 1.5e12))>>>
some1 .-. some2
MkSomeNetSize SB (MkNetBytes (MkBytes 5.0e11))
This respects SomeNetSize
's equivalence-class base Eq
.
module Numeric.Algebra
module Numeric.Literal.Integer
module Numeric.Literal.Rational
Text
Pretty Printing
We provide several formatters for pretty-printing different byte types.
>>>
import Data.Default (Default (def))
>>>
let bf = MkFloatingFormatter (Just 2)
>>>
let b = MkNetBytesP @Up @G @Float 203.301
>>>
formatSizedDirected bf def def b
"203.30 gb up"
module Data.Bytes.Formatting
Parsing
Represents a megaparsec parser. Used for parsing byte types from
Text
.
Since: 0.1
Instances
Parser Direction Source # | Since: 0.1 |
Parser Size Source # | Since: 0.1 |
Read n => Parser (SomeSize n) Source # | Since: 0.1 |
Read n => Parser (SomeNet n) Source # | Since: 0.1 |
Read n => Parser (Bytes s n) Source # | Since: 0.1 |
Read n => Parser (SomeNetDir s n) Source # | Since: 0.1 |
Defined in Data.Bytes.Network.Internal | |
Read n => Parser (SomeNetSize d n) Source # | Since: 0.1 |
Defined in Data.Bytes.Network.Internal | |
Read n => Parser (NetBytes d s n) Source # | Since: 0.1 |
parse :: Parser a => Text -> Either Text a Source #
Parses various byte types from Text
. Parsing is
lenient in general. We support:
- Case-insensitivity.
- Optional leading/internal/trailing whitespace.
- Flexible names.
Bytes Examples
>>>
import Data.Bytes (Bytes, Size (..), SomeSize)
>>>
parse @(Bytes M Int) "70"
Right (MkBytes 70)
>>>
parse @(SomeSize Float) "100.45 kilobytes"
Right (MkSomeSize SK (MkBytes 100.45))
>>>
parse @(SomeSize Word) "2300G"
Right (MkSomeSize SG (MkBytes 2300))
>>>
parse @(SomeSize Float) "5.5 tb"
Right (MkSomeSize ST (MkBytes 5.5))
Network Examples
>>>
import Data.Bytes.Network (Direction (..), NetBytes, SomeNet, SomeNetDir, SomeNetSize)
>>>
parse @(NetBytes Up M Int) "70"
Right (MkNetBytes (MkBytes 70))
>>>
parse @(SomeNetSize Down Float) "100.45 kilobytes"
Right (MkSomeNetSize SK (MkNetBytes (MkBytes 100.45)))
>>>
parse @(SomeNetSize Up Word) "2300G"
Right (MkSomeNetSize SG (MkNetBytes (MkBytes 2300)))
>>>
parse @(SomeNetDir T Word) "2300 up"
Right (MkSomeNetDir SUp (MkNetBytes (MkBytes 2300)))
>>>
parse @(SomeNetDir M Word) "2300D"
Right (MkSomeNetDir SDown (MkNetBytes (MkBytes 2300)))
>>>
parse @(SomeNet Float) "5.5 tb Up"
Right (MkSomeNet SUp ST (MkNetBytes (MkBytes 5.5)))
>>>
parse @(SomeNet Float) "5.5 megabytes DOWN"
Right (MkSomeNet SDown SM (MkNetBytes (MkBytes 5.5)))
Since: 0.1
Optics
Core
_MkSomeNetSize :: forall (s :: Size) (d :: Direction) n. (FromInteger n, MGroup n, SingSize s) => Iso' (SomeNetSize d n) (NetBytes d s n) Source #
Iso'
between SomeNetSize
and underlying NetBytes
. Performs any
necessary conversions when going from SomeNetSize d n -> NetBytes d s n
.
Examples
>>>
import Optics.Core (review, view)
>>>
review _MkSomeNetSize (MkNetBytesP @Up @K @Int 70)
MkSomeNetSize SK (MkNetBytes (MkBytes 70))
>>>
(view _MkSomeNetSize (hideSize $ MkNetBytesP @Up @K @Int 70)) :: NetBytes Up B Int
MkNetBytes (MkBytes 70000)
Since: 0.1
_MkSomeNetDir :: forall (s :: Size) (d :: Direction) n. SingDirection d => Review (SomeNetDir s n) (NetBytes d s n) Source #
Review
between SomeNetDir
and underlying NetBytes
. This is not an
iso (i.e. only allows NetBytes -> SomeNetDir
) because the opposite
direction would require dropping the Direction
and the user arbitrarily
choosing a new one.
Examples
>>>
import Optics.Core (review)
>>>
review _MkSomeNetDir (MkNetBytesP @Up @K @Int 70)
MkSomeNetDir SUp (MkNetBytes (MkBytes 70))
Since: 0.1
_MkSomeNet :: forall (s :: Size) (d :: Direction) n. (SingDirection d, SingSize s) => Review (SomeNet n) (NetBytes d s n) Source #
Review
between SomeNet
and underlying NetBytes
. This is not an
iso (i.e. only allows NetBytes -> SomeNet
) because the opposite
direction would require dropping the Direction
and the user arbitrarily
choosing a new one.
Examples
>>>
import Optics.Core (review)
>>>
review _MkSomeNet (MkNetBytesP @Up @K @Int 70)
MkSomeNet SUp SK (MkNetBytes (MkBytes 70))
Since: 0.1
Size
Direction
Reexports
class Default a where Source #
A class for types with a default value.
Nothing
The default value for this type.
Instances
Default All | |
Defined in Data.Default.Class | |
Default Any | |
Defined in Data.Default.Class | |
Default CClock | |
Defined in Data.Default.Class | |
Default CDouble | |
Defined in Data.Default.Class | |
Default CFloat | |
Defined in Data.Default.Class | |
Default CInt | |
Defined in Data.Default.Class | |
Default CIntMax | |
Defined in Data.Default.Class | |
Default CIntPtr | |
Defined in Data.Default.Class | |
Default CLLong | |
Defined in Data.Default.Class | |
Default CLong | |
Defined in Data.Default.Class | |
Default CPtrdiff | |
Defined in Data.Default.Class | |
Default CSUSeconds | |
Defined in Data.Default.Class def :: CSUSeconds Source # | |
Default CShort | |
Defined in Data.Default.Class | |
Default CSigAtomic | |
Defined in Data.Default.Class def :: CSigAtomic Source # | |
Default CSize | |
Defined in Data.Default.Class | |
Default CTime | |
Defined in Data.Default.Class | |
Default CUInt | |
Defined in Data.Default.Class | |
Default CUIntMax | |
Defined in Data.Default.Class | |
Default CUIntPtr | |
Defined in Data.Default.Class | |
Default CULLong | |
Defined in Data.Default.Class | |
Default CULong | |
Defined in Data.Default.Class | |
Default CUSeconds | |
Defined in Data.Default.Class | |
Default CUShort | |
Defined in Data.Default.Class | |
Default Int16 | |
Defined in Data.Default.Class | |
Default Int32 | |
Defined in Data.Default.Class | |
Default Int64 | |
Defined in Data.Default.Class | |
Default Int8 | |
Defined in Data.Default.Class | |
Default Word16 | |
Defined in Data.Default.Class | |
Default Word32 | |
Defined in Data.Default.Class | |
Default Word64 | |
Defined in Data.Default.Class | |
Default Word8 | |
Defined in Data.Default.Class | |
Default Ordering | |
Defined in Data.Default.Class | |
Default DirectedFormatter Source # | Since: 0.1 |
Defined in Data.Bytes.Formatting.Direction | |
Default DirectionFormat Source # | Since: 0.1 |
Defined in Data.Bytes.Formatting.Direction | |
Default SizeFormat Source # | Since: 0.1 |
Defined in Data.Bytes.Formatting.Size def :: SizeFormat Source # | |
Default SizedFormatter Source # | |
Defined in Data.Bytes.Formatting.Size def :: SizedFormatter Source # | |
Default Integer | |
Defined in Data.Default.Class | |
Default () | |
Defined in Data.Default.Class | |
Default Double | |
Defined in Data.Default.Class | |
Default Float | |
Defined in Data.Default.Class | |
Default Int | |
Defined in Data.Default.Class | |
Default Word | |
Defined in Data.Default.Class | |
(Default a, RealFloat a) => Default (Complex a) | |
Defined in Data.Default.Class | |
Default (First a) | |
Defined in Data.Default.Class | |
Default (Last a) | |
Defined in Data.Default.Class | |
Default a => Default (Dual a) | |
Defined in Data.Default.Class | |
Default (Endo a) | |
Defined in Data.Default.Class | |
Num a => Default (Product a) | |
Defined in Data.Default.Class | |
Num a => Default (Sum a) | |
Defined in Data.Default.Class | |
Integral a => Default (Ratio a) | |
Defined in Data.Default.Class | |
Default a => Default (IO a) | |
Defined in Data.Default.Class | |
Default (Maybe a) | |
Defined in Data.Default.Class | |
Default [a] | |
Defined in Data.Default.Class | |
(Default a, Default b) => Default (a, b) | |
Defined in Data.Default.Class | |
Default r => Default (e -> r) | |
Defined in Data.Default.Class | |
(Default a, Default b, Default c) => Default (a, b, c) | |
Defined in Data.Default.Class | |
(Default a, Default b, Default c, Default d) => Default (a, b, c, d) | |
Defined in Data.Default.Class | |
(Default a, Default b, Default c, Default d, Default e) => Default (a, b, c, d, e) | |
Defined in Data.Default.Class | |
(Default a, Default b, Default c, Default d, Default e, Default f) => Default (a, b, c, d, e, f) | |
Defined in Data.Default.Class | |
(Default a, Default b, Default c, Default d, Default e, Default f, Default g) => Default (a, b, c, d, e, f, g) | |
Defined in Data.Default.Class |