{-# LANGUAGE CPP #-}
{-# LANGUAGE UndecidableInstances #-}
module Data.Bytes.Network.Internal
(
NetBytes (.., MkNetBytesP),
_MkNetBytes,
netToSSize,
netToSDirection,
SomeNetSize (..),
_MkSomeNetSize,
someNetSizeToSDirection,
SomeNetDir (..),
_MkSomeNetDir,
someNetDirToSSize,
SomeNet (..),
_MkSomeNet,
)
where
#if !MIN_VERSION_base(4, 18, 0)
import Control.Applicative (liftA2)
#endif
import Control.DeepSeq (NFData (rnf), deepseq)
import Data.Bounds
( AnyLowerBounded,
AnyUpperBounded,
LowerBounded,
LowerBoundless,
UpperBounded,
UpperBoundless,
)
import Data.Bytes.Class.Conversion (Conversion (Converted, convert_))
import Data.Bytes.Class.Normalize (Normalize (Norm, normalize))
import Data.Bytes.Class.Parser (Parser (parser))
import Data.Bytes.Class.Parser qualified as Parser
import Data.Bytes.Class.RawNumeric (RawNumeric (Raw, toRaw))
import Data.Bytes.Internal (Bytes (MkBytes), SomeSize (MkSomeSize))
import Data.Bytes.Network.Direction
( Directed,
Direction (Down, Up),
SDirection (SDown, SUp),
SingDirection (singDirection),
)
import Data.Bytes.Network.Direction qualified as Direction
import Data.Bytes.Size
( SSize (SB, SE, SG, SK, SM, SP, ST, SY, SZ),
SingSize (singSize),
Size (B, E, G, K, M, P, T, Y, Z),
Sized (hideSize),
)
import Data.Bytes.Size qualified as Size
import Data.Hashable (Hashable (hashWithSalt))
import Data.Kind (Type)
import GHC.Generics (Generic)
#if MIN_VERSION_base(4, 16, 0)
import GHC.Records (HasField (getField))
#endif
import Numeric.Algebra
( AGroup ((.-.)),
AMonoid (zero),
ASemigroup ((.+.)),
Field,
MGroup,
MSemiSpace ((.*)),
MSemigroup,
MSpace ((.%)),
Module,
Normed (norm),
Ring,
Semifield,
Semimodule,
Semiring,
SemivectorSpace,
VectorSpace,
)
import Numeric.Literal.Integer (FromInteger (afromInteger))
import Numeric.Literal.Rational (FromRational (afromRational))
import Optics.Core
( A_Getter,
An_Iso,
Iso',
LabelOptic (labelOptic),
Review,
iso,
to,
unto,
)
import Text.Megaparsec qualified as MP
import Text.Megaparsec.Char qualified as MPC
type NetBytes :: Direction -> Size -> Type -> Type
newtype NetBytes (d :: Direction) (s :: Size) (n :: Type) = MkNetBytes (Bytes s n)
deriving stock
(
NetBytes d s n -> NetBytes d s n -> Bool
(NetBytes d s n -> NetBytes d s n -> Bool)
-> (NetBytes d s n -> NetBytes d s n -> Bool)
-> Eq (NetBytes d s n)
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
forall (d :: Direction) (s :: Size) n.
Eq n =>
NetBytes d s n -> NetBytes d s n -> Bool
$c== :: forall (d :: Direction) (s :: Size) n.
Eq n =>
NetBytes d s n -> NetBytes d s n -> Bool
== :: NetBytes d s n -> NetBytes d s n -> Bool
$c/= :: forall (d :: Direction) (s :: Size) n.
Eq n =>
NetBytes d s n -> NetBytes d s n -> Bool
/= :: NetBytes d s n -> NetBytes d s n -> Bool
Eq,
(forall a b. (a -> b) -> NetBytes d s a -> NetBytes d s b)
-> (forall a b. a -> NetBytes d s b -> NetBytes d s a)
-> Functor (NetBytes d s)
forall a b. a -> NetBytes d s b -> NetBytes d s a
forall a b. (a -> b) -> NetBytes d s a -> NetBytes d s b
forall (d :: Direction) (s :: Size) a b.
a -> NetBytes d s b -> NetBytes d s a
forall (d :: Direction) (s :: Size) a b.
(a -> b) -> NetBytes d s a -> NetBytes d s b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
$cfmap :: forall (d :: Direction) (s :: Size) a b.
(a -> b) -> NetBytes d s a -> NetBytes d s b
fmap :: forall a b. (a -> b) -> NetBytes d s a -> NetBytes d s b
$c<$ :: forall (d :: Direction) (s :: Size) a b.
a -> NetBytes d s b -> NetBytes d s a
<$ :: forall a b. a -> NetBytes d s b -> NetBytes d s a
Functor,
(forall x. NetBytes d s n -> Rep (NetBytes d s n) x)
-> (forall x. Rep (NetBytes d s n) x -> NetBytes d s n)
-> Generic (NetBytes d s n)
forall x. Rep (NetBytes d s n) x -> NetBytes d s n
forall x. NetBytes d s n -> Rep (NetBytes d s n) x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall (d :: Direction) (s :: Size) n x.
Rep (NetBytes d s n) x -> NetBytes d s n
forall (d :: Direction) (s :: Size) n x.
NetBytes d s n -> Rep (NetBytes d s n) x
$cfrom :: forall (d :: Direction) (s :: Size) n x.
NetBytes d s n -> Rep (NetBytes d s n) x
from :: forall x. NetBytes d s n -> Rep (NetBytes d s n) x
$cto :: forall (d :: Direction) (s :: Size) n x.
Rep (NetBytes d s n) x -> NetBytes d s n
to :: forall x. Rep (NetBytes d s n) x -> NetBytes d s n
Generic,
Eq (NetBytes d s n)
Eq (NetBytes d s n) =>
(NetBytes d s n -> NetBytes d s n -> Ordering)
-> (NetBytes d s n -> NetBytes d s n -> Bool)
-> (NetBytes d s n -> NetBytes d s n -> Bool)
-> (NetBytes d s n -> NetBytes d s n -> Bool)
-> (NetBytes d s n -> NetBytes d s n -> Bool)
-> (NetBytes d s n -> NetBytes d s n -> NetBytes d s n)
-> (NetBytes d s n -> NetBytes d s n -> NetBytes d s n)
-> Ord (NetBytes d s n)
NetBytes d s n -> NetBytes d s n -> Bool
NetBytes d s n -> NetBytes d s n -> Ordering
NetBytes d s n -> NetBytes d s n -> NetBytes d s n
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
forall (d :: Direction) (s :: Size) n. Ord n => Eq (NetBytes d s n)
forall (d :: Direction) (s :: Size) n.
Ord n =>
NetBytes d s n -> NetBytes d s n -> Bool
forall (d :: Direction) (s :: Size) n.
Ord n =>
NetBytes d s n -> NetBytes d s n -> Ordering
forall (d :: Direction) (s :: Size) n.
Ord n =>
NetBytes d s n -> NetBytes d s n -> NetBytes d s n
$ccompare :: forall (d :: Direction) (s :: Size) n.
Ord n =>
NetBytes d s n -> NetBytes d s n -> Ordering
compare :: NetBytes d s n -> NetBytes d s n -> Ordering
$c< :: forall (d :: Direction) (s :: Size) n.
Ord n =>
NetBytes d s n -> NetBytes d s n -> Bool
< :: NetBytes d s n -> NetBytes d s n -> Bool
$c<= :: forall (d :: Direction) (s :: Size) n.
Ord n =>
NetBytes d s n -> NetBytes d s n -> Bool
<= :: NetBytes d s n -> NetBytes d s n -> Bool
$c> :: forall (d :: Direction) (s :: Size) n.
Ord n =>
NetBytes d s n -> NetBytes d s n -> Bool
> :: NetBytes d s n -> NetBytes d s n -> Bool
$c>= :: forall (d :: Direction) (s :: Size) n.
Ord n =>
NetBytes d s n -> NetBytes d s n -> Bool
>= :: NetBytes d s n -> NetBytes d s n -> Bool
$cmax :: forall (d :: Direction) (s :: Size) n.
Ord n =>
NetBytes d s n -> NetBytes d s n -> NetBytes d s n
max :: NetBytes d s n -> NetBytes d s n -> NetBytes d s n
$cmin :: forall (d :: Direction) (s :: Size) n.
Ord n =>
NetBytes d s n -> NetBytes d s n -> NetBytes d s n
min :: NetBytes d s n -> NetBytes d s n -> NetBytes d s n
Ord,
Int -> NetBytes d s n -> ShowS
[NetBytes d s n] -> ShowS
NetBytes d s n -> String
(Int -> NetBytes d s n -> ShowS)
-> (NetBytes d s n -> String)
-> ([NetBytes d s n] -> ShowS)
-> Show (NetBytes d s n)
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
forall (d :: Direction) (s :: Size) n.
Show n =>
Int -> NetBytes d s n -> ShowS
forall (d :: Direction) (s :: Size) n.
Show n =>
[NetBytes d s n] -> ShowS
forall (d :: Direction) (s :: Size) n.
Show n =>
NetBytes d s n -> String
$cshowsPrec :: forall (d :: Direction) (s :: Size) n.
Show n =>
Int -> NetBytes d s n -> ShowS
showsPrec :: Int -> NetBytes d s n -> ShowS
$cshow :: forall (d :: Direction) (s :: Size) n.
Show n =>
NetBytes d s n -> String
show :: NetBytes d s n -> String
$cshowList :: forall (d :: Direction) (s :: Size) n.
Show n =>
[NetBytes d s n] -> ShowS
showList :: [NetBytes d s n] -> ShowS
Show
)
deriving anyclass
(
NetBytes d s n -> ()
(NetBytes d s n -> ()) -> NFData (NetBytes d s n)
forall a. (a -> ()) -> NFData a
forall (d :: Direction) (s :: Size) n.
NFData n =>
NetBytes d s n -> ()
$crnf :: forall (d :: Direction) (s :: Size) n.
NFData n =>
NetBytes d s n -> ()
rnf :: NetBytes d s n -> ()
NFData
)
deriving
(
Maybe (NetBytes d s n)
Maybe (NetBytes d s n) -> AnyLowerBounded (NetBytes d s n)
forall a. Maybe a -> AnyLowerBounded a
forall (d :: Direction) (s :: Size) n.
AnyLowerBounded n =>
Maybe (NetBytes d s n)
$csomeLowerBound :: forall (d :: Direction) (s :: Size) n.
AnyLowerBounded n =>
Maybe (NetBytes d s n)
someLowerBound :: Maybe (NetBytes d s n)
AnyLowerBounded,
Maybe (NetBytes d s n)
Maybe (NetBytes d s n) -> AnyUpperBounded (NetBytes d s n)
forall a. Maybe a -> AnyUpperBounded a
forall (d :: Direction) (s :: Size) n.
AnyUpperBounded n =>
Maybe (NetBytes d s n)
$csomeUpperBound :: forall (d :: Direction) (s :: Size) n.
AnyUpperBounded n =>
Maybe (NetBytes d s n)
someUpperBound :: Maybe (NetBytes d s n)
AnyUpperBounded,
Eq (NetBytes d s n)
Eq (NetBytes d s n) =>
(Int -> NetBytes d s n -> Int)
-> (NetBytes d s n -> Int) -> Hashable (NetBytes d s n)
Int -> NetBytes d s n -> Int
NetBytes d s n -> Int
forall a. Eq a => (Int -> a -> Int) -> (a -> Int) -> Hashable a
forall (d :: Direction) (s :: Size) n.
Hashable n =>
Eq (NetBytes d s n)
forall (d :: Direction) (s :: Size) n.
Hashable n =>
Int -> NetBytes d s n -> Int
forall (d :: Direction) (s :: Size) n.
Hashable n =>
NetBytes d s n -> Int
$chashWithSalt :: forall (d :: Direction) (s :: Size) n.
Hashable n =>
Int -> NetBytes d s n -> Int
hashWithSalt :: Int -> NetBytes d s n -> Int
$chash :: forall (d :: Direction) (s :: Size) n.
Hashable n =>
NetBytes d s n -> Int
hash :: NetBytes d s n -> Int
Hashable,
NetBytes d s n
NetBytes d s n -> LowerBounded (NetBytes d s n)
forall a. a -> LowerBounded a
forall (d :: Direction) (s :: Size) n.
LowerBounded n =>
NetBytes d s n
$clowerBound :: forall (d :: Direction) (s :: Size) n.
LowerBounded n =>
NetBytes d s n
lowerBound :: NetBytes d s n
LowerBounded,
LowerBoundless (NetBytes d s n)
forall a. LowerBoundless a
LowerBoundless,
NetBytes d s n
NetBytes d s n -> UpperBounded (NetBytes d s n)
forall a. a -> UpperBounded a
forall (d :: Direction) (s :: Size) n.
UpperBounded n =>
NetBytes d s n
$cupperBound :: forall (d :: Direction) (s :: Size) n.
UpperBounded n =>
NetBytes d s n
upperBound :: NetBytes d s n
UpperBounded,
UpperBoundless (NetBytes d s n)
forall a. UpperBoundless a
UpperBoundless
)
via n
pattern MkNetBytesP :: forall d s n. n -> NetBytes d s n
pattern $mMkNetBytesP :: forall {r} {d :: Direction} {s :: Size} {n}.
NetBytes d s n -> (n -> r) -> ((# #) -> r) -> r
$bMkNetBytesP :: forall (d :: Direction) (s :: Size) n. n -> NetBytes d s n
MkNetBytesP x <-
MkNetBytes (MkBytes x)
where
MkNetBytesP n
x = Bytes s n -> NetBytes d s n
forall (d :: Direction) (s :: Size) n. Bytes s n -> NetBytes d s n
MkNetBytes (n -> Bytes s n
forall (s :: Size) n. n -> Bytes s n
MkBytes n
x)
{-# COMPLETE MkNetBytesP #-}
netToSDirection :: (SingDirection d) => NetBytes d s n -> SDirection d
netToSDirection :: forall (d :: Direction) (s :: Size) n.
SingDirection d =>
NetBytes d s n -> SDirection d
netToSDirection NetBytes d s n
_ = SDirection d
forall (d :: Direction). SingDirection d => SDirection d
singDirection
{-# INLINE netToSDirection #-}
netToSSize :: (SingSize s) => NetBytes d s n -> SSize s
netToSSize :: forall (s :: Size) (d :: Direction) n.
SingSize s =>
NetBytes d s n -> SSize s
netToSSize NetBytes d s n
_ = SSize s
forall (s :: Size). SingSize s => SSize s
singSize
{-# INLINE netToSSize #-}
_MkNetBytes :: forall s d n. Iso' (NetBytes d s n) (Bytes s n)
_MkNetBytes :: forall (s :: Size) (d :: Direction) n.
Iso' (NetBytes d s n) (Bytes s n)
_MkNetBytes = (NetBytes d s n -> Bytes s n)
-> (Bytes s n -> NetBytes d s n)
-> Iso (NetBytes d s n) (NetBytes d s n) (Bytes s n) (Bytes s n)
forall s a b t. (s -> a) -> (b -> t) -> Iso s t a b
iso (\(MkNetBytes Bytes s n
x) -> Bytes s n
x) Bytes s n -> NetBytes d s n
forall (d :: Direction) (s :: Size) n. Bytes s n -> NetBytes d s n
MkNetBytes
{-# INLINE _MkNetBytes #-}
#if MIN_VERSION_base(4, 16, 0)
instance HasField "unNetBytes" (NetBytes d s n) n where
getField :: NetBytes d s n -> n
getField (MkNetBytesP n
x) = n
x
#endif
instance
( k ~ An_Iso,
a ~ n,
b ~ n
) =>
LabelOptic "unNetBytes" k (NetBytes d s n) (NetBytes d s n) a b
where
labelOptic :: Optic k NoIx (NetBytes d s n) (NetBytes d s n) a b
labelOptic = (NetBytes d s n -> a)
-> (b -> NetBytes d s n)
-> Iso (NetBytes d s n) (NetBytes d s n) a b
forall s a b t. (s -> a) -> (b -> t) -> Iso s t a b
iso (\(MkNetBytesP n
x) -> a
n
x) b -> NetBytes d s n
b -> NetBytes d s b
forall (d :: Direction) (s :: Size) n. n -> NetBytes d s n
MkNetBytesP
{-# INLINE labelOptic #-}
instance Applicative (NetBytes d s) where
pure :: forall a. a -> NetBytes d s a
pure = Bytes s a -> NetBytes d s a
forall (d :: Direction) (s :: Size) n. Bytes s n -> NetBytes d s n
MkNetBytes (Bytes s a -> NetBytes d s a)
-> (a -> Bytes s a) -> a -> NetBytes d s a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> Bytes s a
forall a. a -> Bytes s a
forall (f :: * -> *) a. Applicative f => a -> f a
pure
{-# INLINE pure #-}
MkNetBytes Bytes s (a -> b)
f <*> :: forall a b.
NetBytes d s (a -> b) -> NetBytes d s a -> NetBytes d s b
<*> MkNetBytes Bytes s a
x = Bytes s b -> NetBytes d s b
forall (d :: Direction) (s :: Size) n. Bytes s n -> NetBytes d s n
MkNetBytes (Bytes s b -> NetBytes d s b) -> Bytes s b -> NetBytes d s b
forall a b. (a -> b) -> a -> b
$ Bytes s (a -> b)
f Bytes s (a -> b) -> Bytes s a -> Bytes s b
forall a b. Bytes s (a -> b) -> Bytes s a -> Bytes s b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Bytes s a
x
{-# INLINE (<*>) #-}
instance Monad (NetBytes d s) where
MkNetBytes Bytes s a
x >>= :: forall a b.
NetBytes d s a -> (a -> NetBytes d s b) -> NetBytes d s b
>>= a -> NetBytes d s b
f = Bytes s b -> NetBytes d s b
forall (d :: Direction) (s :: Size) n. Bytes s n -> NetBytes d s n
MkNetBytes (Bytes s b -> NetBytes d s b) -> Bytes s b -> NetBytes d s b
forall a b. (a -> b) -> a -> b
$ Bytes s a
x Bytes s a -> (a -> Bytes s b) -> Bytes s b
forall a b. Bytes s a -> (a -> Bytes s b) -> Bytes s b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= (NetBytes d s b -> Bytes s b
forall (d :: Direction) (s :: Size) n. NetBytes d s n -> Bytes s n
unNetBytes (NetBytes d s b -> Bytes s b)
-> (a -> NetBytes d s b) -> a -> Bytes s b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> NetBytes d s b
f)
{-# INLINE (>>=) #-}
instance Foldable (NetBytes d s) where
foldr :: forall a b. (a -> b -> b) -> b -> NetBytes d s a -> b
foldr a -> b -> b
f b
e (MkNetBytesP a
x) = a -> b -> b
f a
x b
e
{-# INLINE foldr #-}
instance Traversable (NetBytes d s) where
traverse :: forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> NetBytes d s a -> f (NetBytes d s b)
traverse a -> f b
f (MkNetBytesP a
x) = b -> NetBytes d s b
forall (d :: Direction) (s :: Size) n. n -> NetBytes d s n
MkNetBytesP (b -> NetBytes d s b) -> f b -> f (NetBytes d s b)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> a -> f b
f a
x
{-# INLINE traverse #-}
sequenceA :: forall (f :: * -> *) a.
Applicative f =>
NetBytes d s (f a) -> f (NetBytes d s a)
sequenceA (MkNetBytesP f a
x) = a -> NetBytes d s a
forall (d :: Direction) (s :: Size) n. n -> NetBytes d s n
MkNetBytesP (a -> NetBytes d s a) -> f a -> f (NetBytes d s a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> f a
x
{-# INLINE sequenceA #-}
instance (FromInteger n) => FromInteger (NetBytes d s n) where
afromInteger :: HasCallStack => Integer -> NetBytes d s n
afromInteger = Bytes s n -> NetBytes d s n
forall (d :: Direction) (s :: Size) n. Bytes s n -> NetBytes d s n
MkNetBytes (Bytes s n -> NetBytes d s n)
-> (Integer -> Bytes s n) -> Integer -> NetBytes d s n
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Integer -> Bytes s n
forall a. (FromInteger a, HasCallStack) => Integer -> a
afromInteger
{-# INLINE afromInteger #-}
instance (FromRational n) => FromRational (NetBytes d s n) where
afromRational :: HasCallStack => Rational -> NetBytes d s n
afromRational = Bytes s n -> NetBytes d s n
forall (d :: Direction) (s :: Size) n. Bytes s n -> NetBytes d s n
MkNetBytes (Bytes s n -> NetBytes d s n)
-> (Rational -> Bytes s n) -> Rational -> NetBytes d s n
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Rational -> Bytes s n
forall a. (FromRational a, HasCallStack) => Rational -> a
afromRational
{-# INLINE afromRational #-}
instance (ASemigroup n) => ASemigroup (NetBytes d s n) where
.+. :: NetBytes d s n -> NetBytes d s n -> NetBytes d s n
(.+.) = (n -> n -> n) -> NetBytes d s n -> NetBytes d s n -> NetBytes d s n
forall a b c.
(a -> b -> c) -> NetBytes d s a -> NetBytes d s b -> NetBytes d s c
forall (f :: * -> *) a b c.
Applicative f =>
(a -> b -> c) -> f a -> f b -> f c
liftA2 n -> n -> n
forall s. ASemigroup s => s -> s -> s
(.+.)
{-# INLINE (.+.) #-}
instance (AMonoid n) => AMonoid (NetBytes d s n) where
zero :: NetBytes d s n
zero = Bytes s n -> NetBytes d s n
forall (d :: Direction) (s :: Size) n. Bytes s n -> NetBytes d s n
MkNetBytes Bytes s n
forall m. AMonoid m => m
zero
{-# INLINE zero #-}
instance (AGroup n) => AGroup (NetBytes d s n) where
.-. :: NetBytes d s n -> NetBytes d s n -> NetBytes d s n
(.-.) = (n -> n -> n) -> NetBytes d s n -> NetBytes d s n -> NetBytes d s n
forall a b c.
(a -> b -> c) -> NetBytes d s a -> NetBytes d s b -> NetBytes d s c
forall (f :: * -> *) a b c.
Applicative f =>
(a -> b -> c) -> f a -> f b -> f c
liftA2 n -> n -> n
forall g. AGroup g => g -> g -> g
(.-.)
{-# INLINE (.-.) #-}
instance (Normed n) => Normed (NetBytes d s n) where
norm :: NetBytes d s n -> NetBytes d s n
norm (MkNetBytes Bytes s n
b) = Bytes s n -> NetBytes d s n
forall (d :: Direction) (s :: Size) n. Bytes s n -> NetBytes d s n
MkNetBytes (Bytes s n -> Bytes s n
forall s. Normed s => s -> s
norm Bytes s n
b)
{-# INLINE norm #-}
instance (MSemigroup n) => MSemiSpace (NetBytes d s n) n where
MkNetBytes Bytes s n
x .* :: NetBytes d s n -> n -> NetBytes d s n
.* n
k = Bytes s n -> NetBytes d s n
forall (d :: Direction) (s :: Size) n. Bytes s n -> NetBytes d s n
MkNetBytes (Bytes s n -> NetBytes d s n) -> Bytes s n -> NetBytes d s n
forall a b. (a -> b) -> a -> b
$ Bytes s n
x Bytes s n -> n -> Bytes s n
forall m r. MSemiSpace m r => m -> r -> m
.* n
k
{-# INLINE (.*) #-}
instance (MGroup n) => MSpace (NetBytes d s n) n where
MkNetBytes Bytes s n
x .% :: NetBytes d s n -> n -> NetBytes d s n
.% n
k = Bytes s n -> NetBytes d s n
forall (d :: Direction) (s :: Size) n. Bytes s n -> NetBytes d s n
MkNetBytes (Bytes s n -> NetBytes d s n) -> Bytes s n -> NetBytes d s n
forall a b. (a -> b) -> a -> b
$ Bytes s n
x Bytes s n -> n -> Bytes s n
forall v k. MSpace v k => v -> k -> v
.% n
k
{-# INLINEABLE (.%) #-}
instance (Semiring n) => Semimodule (NetBytes d s n) n
instance (Ring n) => Module (NetBytes d s n) n
instance (Semifield n) => SemivectorSpace (NetBytes d s n) n
instance (Field n) => VectorSpace (NetBytes d s n) n
instance (FromInteger n, MGroup n, SingSize s) => Conversion (NetBytes d s n) where
type Converted t (NetBytes d s n) = NetBytes d t n
convert_ :: forall t. (SingSize t) => NetBytes d s n -> NetBytes d t n
convert_ :: forall (t :: Size). SingSize t => NetBytes d s n -> NetBytes d t n
convert_ (MkNetBytes Bytes s n
x) = Bytes t n -> NetBytes d t n
forall (d :: Direction) (s :: Size) n. Bytes s n -> NetBytes d s n
MkNetBytes (Bytes t n -> NetBytes d t n) -> Bytes t n -> NetBytes d t n
forall a b. (a -> b) -> a -> b
$ Bytes s n -> Converted t (Bytes s n)
forall a (t :: Size).
(Conversion a, SingSize t) =>
a -> Converted t a
forall (t :: Size).
SingSize t =>
Bytes s n -> Converted t (Bytes s n)
convert_ Bytes s n
x
instance (FromInteger n, MGroup n, Normed n, Ord n, SingSize s) => Normalize (NetBytes d s n) where
type Norm (NetBytes d s n) = SomeNetSize d n
normalize :: NetBytes d s n -> Norm (NetBytes d s n)
normalize (MkNetBytes Bytes s n
bytes) = case Bytes s n -> Norm (Bytes s n)
forall a. Normalize a => a -> Norm a
normalize Bytes s n
bytes of
MkSomeSize SSize s
sz Bytes s n
bytes' -> SSize s -> NetBytes d s n -> SomeNetSize d n
forall (d :: Size) (d :: Direction) n.
SSize d -> NetBytes d d n -> SomeNetSize d n
MkSomeNetSize SSize s
sz (NetBytes d s n -> SomeNetSize d n)
-> NetBytes d s n -> SomeNetSize d n
forall a b. (a -> b) -> a -> b
$ Bytes s n -> NetBytes d s n
forall (d :: Direction) (s :: Size) n. Bytes s n -> NetBytes d s n
MkNetBytes Bytes s n
bytes'
{-# INLINE normalize #-}
instance (SingSize s) => Sized (NetBytes d s n) where
type HideSize (NetBytes d s n) = SomeNetSize d n
sizeOf :: NetBytes d s n -> Size
sizeOf = SSize s -> Size
forall (s :: Size). SSize s -> Size
Size.ssizeToSize (SSize s -> Size)
-> (NetBytes d s n -> SSize s) -> NetBytes d s n -> Size
forall b c a. (b -> c) -> (a -> b) -> a -> c
. NetBytes d s n -> SSize s
forall (s :: Size) (d :: Direction) n.
SingSize s =>
NetBytes d s n -> SSize s
netToSSize
{-# INLINE sizeOf #-}
hideSize :: NetBytes d s n -> HideSize (NetBytes d s n)
hideSize b :: NetBytes d s n
b@(MkNetBytes Bytes s n
_) = SSize s -> NetBytes d s n -> SomeNetSize d n
forall (d :: Size) (d :: Direction) n.
SSize d -> NetBytes d d n -> SomeNetSize d n
MkSomeNetSize (forall (s :: Size). SingSize s => SSize s
singSize @s) NetBytes d s n
b
{-# INLINE hideSize #-}
instance (SingDirection d) => Directed (NetBytes d s n) where
type HideDirection (NetBytes d s n) = SomeNetDir s n
directionOf :: NetBytes d s n -> Direction
directionOf = SDirection d -> Direction
forall (d :: Direction). SDirection d -> Direction
Direction.sdirectionToDirection (SDirection d -> Direction)
-> (NetBytes d s n -> SDirection d) -> NetBytes d s n -> Direction
forall b c a. (b -> c) -> (a -> b) -> a -> c
. NetBytes d s n -> SDirection d
forall (d :: Direction) (s :: Size) n.
SingDirection d =>
NetBytes d s n -> SDirection d
netToSDirection
{-# INLINE directionOf #-}
hideDirection :: NetBytes d s n -> HideDirection (NetBytes d s n)
hideDirection b :: NetBytes d s n
b@(MkNetBytes Bytes s n
_) = SDirection d -> NetBytes d s n -> SomeNetDir s n
forall (d :: Direction) (s :: Size) n.
SDirection d -> NetBytes d s n -> SomeNetDir s n
MkSomeNetDir (forall (d :: Direction). SingDirection d => SDirection d
singDirection @d) NetBytes d s n
b
{-# INLINE hideDirection #-}
instance RawNumeric (NetBytes d s n) where
type Raw (NetBytes d s n) = n
toRaw :: NetBytes d s n -> Raw (NetBytes d s n)
toRaw (MkNetBytes Bytes s n
b) = Bytes s n -> Raw (Bytes s n)
forall a. RawNumeric a => a -> Raw a
toRaw Bytes s n
b
{-# INLINE toRaw #-}
instance (Read n) => Parser (NetBytes d s n) where
parser :: Parsec Void Text (NetBytes d s n)
parser = Bytes s n -> NetBytes d s n
forall (d :: Direction) (s :: Size) n. Bytes s n -> NetBytes d s n
MkNetBytes (Bytes s n -> NetBytes d s n)
-> ParsecT Void Text Identity (Bytes s n)
-> Parsec Void Text (NetBytes d s n)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT Void Text Identity (Bytes s n)
forall a. Parser a => Parsec Void Text a
parser
{-# INLINE parser #-}
type SomeNetSize :: Direction -> Type -> Type
data SomeNetSize (d :: Direction) (n :: Type) where
MkSomeNetSize :: SSize s -> NetBytes d s n -> SomeNetSize d n
_MkSomeNetSize :: forall s d n. (FromInteger n, MGroup n, SingSize s) => Iso' (SomeNetSize d n) (NetBytes d s n)
_MkSomeNetSize :: forall (s :: Size) (d :: Direction) n.
(FromInteger n, MGroup n, SingSize s) =>
Iso' (SomeNetSize d n) (NetBytes d s n)
_MkSomeNetSize = (SomeNetSize d n -> NetBytes d s n)
-> (NetBytes d s n -> SomeNetSize d n)
-> Iso
(SomeNetSize d n)
(SomeNetSize d n)
(NetBytes d s n)
(NetBytes d s n)
forall s a b t. (s -> a) -> (b -> t) -> Iso s t a b
iso SomeNetSize d n -> Converted s (SomeNetSize d n)
SomeNetSize d n -> NetBytes d s n
forall a (t :: Size).
(Conversion a, SingSize t) =>
a -> Converted t a
forall (t :: Size).
SingSize t =>
SomeNetSize d n -> Converted t (SomeNetSize d n)
convert_ NetBytes d s n -> HideSize (NetBytes d s n)
NetBytes d s n -> SomeNetSize d n
forall a. Sized a => a -> HideSize a
hideSize
{-# INLINE _MkSomeNetSize #-}
deriving stock instance (Show n) => Show (SomeNetSize d n)
#if MIN_VERSION_base(4, 16, 0)
instance HasField "unSomeNetSize" (SomeNetSize d n) n where
getField :: SomeNetSize d n -> n
getField (MkSomeNetSize SSize s
_ (MkNetBytesP n
x)) = n
x
#endif
instance
( k ~ A_Getter,
a ~ n,
b ~ n
) =>
LabelOptic "unSomeNetSize" k (SomeNetSize d n) (SomeNetSize d n) a b
where
labelOptic :: Optic k NoIx (SomeNetSize d n) (SomeNetSize d n) a b
labelOptic = (SomeNetSize d n -> a) -> Getter (SomeNetSize d n) a
forall s a. (s -> a) -> Getter s a
to (\(MkSomeNetSize SSize s
_ (MkNetBytesP n
x)) -> a
n
x)
{-# INLINE labelOptic #-}
instance (FromInteger n, Hashable n, MGroup n) => Hashable (SomeNetSize d n) where
hashWithSalt :: Int -> SomeNetSize d n -> Int
hashWithSalt Int
i (MkSomeNetSize SSize s
sz NetBytes d s n
x) =
Int
i Int -> Size -> Int
forall a. Hashable a => Int -> a -> Int
`hashWithSalt` SSize s -> Size
forall (s :: Size). SSize s -> Size
Size.ssizeToSize SSize s
sz Int -> NetBytes d s n -> Int
forall a. Hashable a => Int -> a -> Int
`hashWithSalt` NetBytes d s n
x
instance (NFData n) => NFData (SomeNetSize d n) where
rnf :: SomeNetSize d n -> ()
rnf (MkSomeNetSize SSize s
sz NetBytes d s n
x) = SSize s
sz SSize s -> () -> ()
forall a b. NFData a => a -> b -> b
`deepseq` NetBytes d s n
x NetBytes d s n -> () -> ()
forall a b. NFData a => a -> b -> b
`deepseq` ()
deriving stock instance Functor (SomeNetSize d)
instance Foldable (SomeNetSize d) where
foldr :: forall a b. (a -> b -> b) -> b -> SomeNetSize d a -> b
foldr a -> b -> b
f b
e (MkSomeNetSize SSize s
_ (MkNetBytesP a
x)) = a -> b -> b
f a
x b
e
{-# INLINE foldr #-}
instance Traversable (SomeNetSize d) where
traverse :: forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> SomeNetSize d a -> f (SomeNetSize d b)
traverse a -> f b
f (MkSomeNetSize SSize s
sz (MkNetBytesP a
x)) = SSize s -> NetBytes d s b -> SomeNetSize d b
forall (d :: Size) (d :: Direction) n.
SSize d -> NetBytes d d n -> SomeNetSize d n
MkSomeNetSize SSize s
sz (NetBytes d s b -> SomeNetSize d b)
-> (b -> NetBytes d s b) -> b -> SomeNetSize d b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. b -> NetBytes d s b
forall (d :: Direction) (s :: Size) n. n -> NetBytes d s n
MkNetBytesP (b -> SomeNetSize d b) -> f b -> f (SomeNetSize d b)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> a -> f b
f a
x
{-# INLINE traverse #-}
sequenceA :: forall (f :: * -> *) a.
Applicative f =>
SomeNetSize d (f a) -> f (SomeNetSize d a)
sequenceA (MkSomeNetSize SSize s
sz (MkNetBytesP f a
x)) = SSize s -> NetBytes d s a -> SomeNetSize d a
forall (d :: Size) (d :: Direction) n.
SSize d -> NetBytes d d n -> SomeNetSize d n
MkSomeNetSize SSize s
sz (NetBytes d s a -> SomeNetSize d a)
-> (a -> NetBytes d s a) -> a -> SomeNetSize d a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> NetBytes d s a
forall (d :: Direction) (s :: Size) n. n -> NetBytes d s n
MkNetBytesP (a -> SomeNetSize d a) -> f a -> f (SomeNetSize d a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> f a
x
{-# INLINE sequenceA #-}
instance (Eq n, FromInteger n, MGroup n) => Eq (SomeNetSize d n) where
SomeNetSize d n
x == :: SomeNetSize d n -> SomeNetSize d n -> Bool
== SomeNetSize d n
y = forall a (t :: Size).
(Conversion a, SingSize t) =>
a -> Converted t a
convert_ @_ @B SomeNetSize d n
x NetBytes d 'B n -> NetBytes d 'B n -> Bool
forall a. Eq a => a -> a -> Bool
== SomeNetSize d n -> Converted 'B (SomeNetSize d n)
forall a (t :: Size).
(Conversion a, SingSize t) =>
a -> Converted t a
forall (t :: Size).
SingSize t =>
SomeNetSize d n -> Converted t (SomeNetSize d n)
convert_ SomeNetSize d n
y
{-# INLINE (==) #-}
instance (FromInteger n, MGroup n, Ord n) => Ord (SomeNetSize d n) where
SomeNetSize d n
x <= :: SomeNetSize d n -> SomeNetSize d n -> Bool
<= SomeNetSize d n
y = forall a (t :: Size).
(Conversion a, SingSize t) =>
a -> Converted t a
convert_ @_ @B SomeNetSize d n
x NetBytes d 'B n -> NetBytes d 'B n -> Bool
forall a. Ord a => a -> a -> Bool
<= SomeNetSize d n -> Converted 'B (SomeNetSize d n)
forall a (t :: Size).
(Conversion a, SingSize t) =>
a -> Converted t a
forall (t :: Size).
SingSize t =>
SomeNetSize d n -> Converted t (SomeNetSize d n)
convert_ SomeNetSize d n
y
{-# INLINE (<=) #-}
instance (FromInteger n) => FromInteger (SomeNetSize d n) where
afromInteger :: HasCallStack => Integer -> SomeNetSize d n
afromInteger = SSize 'B -> NetBytes d 'B n -> SomeNetSize d n
forall (d :: Size) (d :: Direction) n.
SSize d -> NetBytes d d n -> SomeNetSize d n
MkSomeNetSize SSize 'B
SB (NetBytes d 'B n -> SomeNetSize d n)
-> (Integer -> NetBytes d 'B n) -> Integer -> SomeNetSize d n
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Integer -> NetBytes d 'B n
forall a. (FromInteger a, HasCallStack) => Integer -> a
afromInteger
{-# INLINE afromInteger #-}
instance (FromRational n) => FromRational (SomeNetSize d n) where
afromRational :: HasCallStack => Rational -> SomeNetSize d n
afromRational = SSize 'B -> NetBytes d 'B n -> SomeNetSize d n
forall (d :: Size) (d :: Direction) n.
SSize d -> NetBytes d d n -> SomeNetSize d n
MkSomeNetSize SSize 'B
SB (NetBytes d 'B n -> SomeNetSize d n)
-> (Rational -> NetBytes d 'B n) -> Rational -> SomeNetSize d n
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Rational -> NetBytes d 'B n
forall a. (FromRational a, HasCallStack) => Rational -> a
afromRational
{-# INLINE afromRational #-}
instance (ASemigroup n, FromInteger n, MGroup n) => ASemigroup (SomeNetSize d n) where
SomeNetSize d n
x .+. :: SomeNetSize d n -> SomeNetSize d n -> SomeNetSize d n
.+. SomeNetSize d n
y = SSize 'B -> NetBytes d 'B n -> SomeNetSize d n
forall (d :: Size) (d :: Direction) n.
SSize d -> NetBytes d d n -> SomeNetSize d n
MkSomeNetSize SSize 'B
SB (NetBytes d 'B n -> SomeNetSize d n)
-> NetBytes d 'B n -> SomeNetSize d n
forall a b. (a -> b) -> a -> b
$ SomeNetSize d n -> Converted 'B (SomeNetSize d n)
forall a (t :: Size).
(Conversion a, SingSize t) =>
a -> Converted t a
forall (t :: Size).
SingSize t =>
SomeNetSize d n -> Converted t (SomeNetSize d n)
convert_ SomeNetSize d n
x NetBytes d 'B n -> NetBytes d 'B n -> NetBytes d 'B n
forall s. ASemigroup s => s -> s -> s
.+. SomeNetSize d n -> Converted 'B (SomeNetSize d n)
forall a (t :: Size).
(Conversion a, SingSize t) =>
a -> Converted t a
forall (t :: Size).
SingSize t =>
SomeNetSize d n -> Converted t (SomeNetSize d n)
convert_ SomeNetSize d n
y
{-# INLINE (.+.) #-}
instance (FromInteger n, Semifield n) => AMonoid (SomeNetSize d n) where
zero :: SomeNetSize d n
zero = SSize 'B -> NetBytes d 'B n -> SomeNetSize d n
forall (d :: Size) (d :: Direction) n.
SSize d -> NetBytes d d n -> SomeNetSize d n
MkSomeNetSize SSize 'B
SB NetBytes d 'B n
forall m. AMonoid m => m
zero
{-# INLINE zero #-}
instance (Field n, FromInteger n) => AGroup (SomeNetSize d n) where
SomeNetSize d n
x .-. :: SomeNetSize d n -> SomeNetSize d n -> SomeNetSize d n
.-. SomeNetSize d n
y = SSize 'B -> NetBytes d 'B n -> SomeNetSize d n
forall (d :: Size) (d :: Direction) n.
SSize d -> NetBytes d d n -> SomeNetSize d n
MkSomeNetSize SSize 'B
SB (NetBytes d 'B n -> SomeNetSize d n)
-> NetBytes d 'B n -> SomeNetSize d n
forall a b. (a -> b) -> a -> b
$ SomeNetSize d n -> Converted 'B (SomeNetSize d n)
forall a (t :: Size).
(Conversion a, SingSize t) =>
a -> Converted t a
forall (t :: Size).
SingSize t =>
SomeNetSize d n -> Converted t (SomeNetSize d n)
convert_ SomeNetSize d n
x NetBytes d 'B n -> NetBytes d 'B n -> NetBytes d 'B n
forall g. AGroup g => g -> g -> g
.-. SomeNetSize d n -> Converted 'B (SomeNetSize d n)
forall a (t :: Size).
(Conversion a, SingSize t) =>
a -> Converted t a
forall (t :: Size).
SingSize t =>
SomeNetSize d n -> Converted t (SomeNetSize d n)
convert_ SomeNetSize d n
y
{-# INLINE (.-.) #-}
instance (MGroup n) => MSemiSpace (SomeNetSize d n) n where
MkSomeNetSize SSize s
sz NetBytes d s n
x .* :: SomeNetSize d n -> n -> SomeNetSize d n
.* n
k = SSize s -> NetBytes d s n -> SomeNetSize d n
forall (d :: Size) (d :: Direction) n.
SSize d -> NetBytes d d n -> SomeNetSize d n
MkSomeNetSize SSize s
sz (NetBytes d s n -> SomeNetSize d n)
-> NetBytes d s n -> SomeNetSize d n
forall a b. (a -> b) -> a -> b
$ NetBytes d s n
x NetBytes d s n -> n -> NetBytes d s n
forall m r. MSemiSpace m r => m -> r -> m
.* n
k
{-# INLINE (.*) #-}
instance (MGroup n) => MSpace (SomeNetSize d n) n where
MkSomeNetSize SSize s
sz NetBytes d s n
x .% :: SomeNetSize d n -> n -> SomeNetSize d n
.% n
k = SSize s -> NetBytes d s n -> SomeNetSize d n
forall (d :: Size) (d :: Direction) n.
SSize d -> NetBytes d d n -> SomeNetSize d n
MkSomeNetSize SSize s
sz (NetBytes d s n -> SomeNetSize d n)
-> NetBytes d s n -> SomeNetSize d n
forall a b. (a -> b) -> a -> b
$ NetBytes d s n
x NetBytes d s n -> n -> NetBytes d s n
forall v k. MSpace v k => v -> k -> v
.% n
k
{-# INLINEABLE (.%) #-}
instance (FromInteger n, Semifield n) => Semimodule (SomeNetSize d n) n
instance (Field n, FromInteger n) => Module (SomeNetSize d n) n
instance (FromInteger n, Semifield n) => SemivectorSpace (SomeNetSize d n) n
instance (FromInteger n, Field n) => VectorSpace (SomeNetSize d n) n
instance (FromInteger n, MGroup n) => Conversion (SomeNetSize d n) where
type Converted t (SomeNetSize d n) = NetBytes d t n
convert_ :: forall t. (SingSize t) => SomeNetSize d n -> NetBytes d t n
convert_ :: forall (t :: Size). SingSize t => SomeNetSize d n -> NetBytes d t n
convert_ (MkSomeNetSize SSize s
sz NetBytes d s n
x) = SSize s -> (SingSize s => NetBytes d t n) -> NetBytes d t n
forall (s :: Size) r. SSize s -> (SingSize s => r) -> r
Size.withSingSize SSize s
sz ((SingSize s => NetBytes d t n) -> NetBytes d t n)
-> (SingSize s => NetBytes d t n) -> NetBytes d t n
forall a b. (a -> b) -> a -> b
$ NetBytes d s n -> Converted t (NetBytes d s n)
forall a (t :: Size).
(Conversion a, SingSize t) =>
a -> Converted t a
forall (t :: Size).
SingSize t =>
NetBytes d s n -> Converted t (NetBytes d s n)
convert_ NetBytes d s n
x
instance (FromInteger n, MGroup n, Normed n, Ord n) => Normalize (SomeNetSize d n) where
type Norm (SomeNetSize d n) = SomeNetSize d n
normalize :: SomeNetSize d n -> Norm (SomeNetSize d n)
normalize (MkSomeNetSize SSize s
sz NetBytes d s n
x) = SSize s
-> (SingSize s => Norm (SomeNetSize d n)) -> Norm (SomeNetSize d n)
forall (s :: Size) r. SSize s -> (SingSize s => r) -> r
Size.withSingSize SSize s
sz ((SingSize s => Norm (SomeNetSize d n)) -> Norm (SomeNetSize d n))
-> (SingSize s => Norm (SomeNetSize d n)) -> Norm (SomeNetSize d n)
forall a b. (a -> b) -> a -> b
$ NetBytes d s n -> Norm (NetBytes d s n)
forall a. Normalize a => a -> Norm a
normalize NetBytes d s n
x
{-# INLINE normalize #-}
instance Sized (SomeNetSize d n) where
type HideSize (SomeNetSize d n) = SomeNetSize d n
sizeOf :: SomeNetSize d n -> Size
sizeOf (MkSomeNetSize SSize s
sz NetBytes d s n
_) = SSize s -> Size
forall (s :: Size). SSize s -> Size
Size.ssizeToSize SSize s
sz
{-# INLINE sizeOf #-}
hideSize :: SomeNetSize d n -> HideSize (SomeNetSize d n)
hideSize = SomeNetSize d n -> HideSize (SomeNetSize d n)
SomeNetSize d n -> SomeNetSize d n
forall a. a -> a
id
{-# INLINE hideSize #-}
instance (SingDirection d) => Directed (SomeNetSize d n) where
type HideDirection (SomeNetSize d n) = SomeNet n
directionOf :: SomeNetSize d n -> Direction
directionOf = SDirection d -> Direction
forall (d :: Direction). SDirection d -> Direction
Direction.sdirectionToDirection (SDirection d -> Direction)
-> (SomeNetSize d n -> SDirection d)
-> SomeNetSize d n
-> Direction
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SomeNetSize d n -> SDirection d
forall (d :: Direction) n.
SingDirection d =>
SomeNetSize d n -> SDirection d
someNetSizeToSDirection
{-# INLINE directionOf #-}
hideDirection :: SomeNetSize d n -> HideDirection (SomeNetSize d n)
hideDirection (MkSomeNetSize SSize s
sz NetBytes d s n
b) = SDirection d -> SSize s -> NetBytes d s n -> SomeNet n
forall (d :: Direction) (s :: Size) n.
SDirection d -> SSize s -> NetBytes d s n -> SomeNet n
MkSomeNet (forall (d :: Direction). SingDirection d => SDirection d
singDirection @d) SSize s
sz NetBytes d s n
b
{-# INLINE hideDirection #-}
instance RawNumeric (SomeNetSize d n) where
type Raw (SomeNetSize d n) = n
toRaw :: SomeNetSize d n -> Raw (SomeNetSize d n)
toRaw (MkSomeNetSize SSize s
_ NetBytes d s n
b) = NetBytes d s n -> Raw (NetBytes d s n)
forall a. RawNumeric a => a -> Raw a
toRaw NetBytes d s n
b
{-# INLINE toRaw #-}
instance (Read n) => Parser (SomeNetSize d n) where
parser :: Parsec Void Text (SomeNetSize d n)
parser = do
MkSomeSize SSize s
sz Bytes s n
bytes <- ParsecT Void Text Identity (SomeSize n)
forall a. Parser a => Parsec Void Text a
parser
SomeNetSize d n -> Parsec Void Text (SomeNetSize d n)
forall a. a -> ParsecT Void Text Identity a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (SomeNetSize d n -> Parsec Void Text (SomeNetSize d n))
-> SomeNetSize d n -> Parsec Void Text (SomeNetSize d n)
forall a b. (a -> b) -> a -> b
$ SSize s -> NetBytes d s n -> SomeNetSize d n
forall (d :: Size) (d :: Direction) n.
SSize d -> NetBytes d d n -> SomeNetSize d n
MkSomeNetSize SSize s
sz (Bytes s n -> NetBytes d s n
forall (d :: Direction) (s :: Size) n. Bytes s n -> NetBytes d s n
MkNetBytes Bytes s n
bytes)
someNetSizeToSDirection :: (SingDirection d) => SomeNetSize d n -> SDirection d
someNetSizeToSDirection :: forall (d :: Direction) n.
SingDirection d =>
SomeNetSize d n -> SDirection d
someNetSizeToSDirection SomeNetSize d n
_ = SDirection d
forall (d :: Direction). SingDirection d => SDirection d
singDirection
{-# INLINE someNetSizeToSDirection #-}
unNetBytes :: NetBytes d s n -> Bytes s n
unNetBytes :: forall (d :: Direction) (s :: Size) n. NetBytes d s n -> Bytes s n
unNetBytes (MkNetBytes Bytes s n
x) = Bytes s n
x
type SomeNetDir :: Size -> Type -> Type
data SomeNetDir (s :: Size) (n :: Type) where
MkSomeNetDir :: SDirection d -> NetBytes d s n -> SomeNetDir s n
someNetDirToSSize :: (SingSize s) => SomeNetDir s n -> SSize s
someNetDirToSSize :: forall (s :: Size) n. SingSize s => SomeNetDir s n -> SSize s
someNetDirToSSize SomeNetDir s n
_ = SSize s
forall (s :: Size). SingSize s => SSize s
singSize
{-# INLINE someNetDirToSSize #-}
_MkSomeNetDir :: forall s d n. (SingDirection d) => Review (SomeNetDir s n) (NetBytes d s n)
_MkSomeNetDir :: forall (s :: Size) (d :: Direction) n.
SingDirection d =>
Review (SomeNetDir s n) (NetBytes d s n)
_MkSomeNetDir = (NetBytes d s n -> SomeNetDir s n)
-> Review (SomeNetDir s n) (NetBytes d s n)
forall b t. (b -> t) -> Review t b
unto (\NetBytes d s n
b -> SDirection d -> NetBytes d s n -> SomeNetDir s n
forall (d :: Direction) (s :: Size) n.
SDirection d -> NetBytes d s n -> SomeNetDir s n
MkSomeNetDir (NetBytes d s n -> SDirection d
forall (d :: Direction) (s :: Size) n.
SingDirection d =>
NetBytes d s n -> SDirection d
netToSDirection NetBytes d s n
b) NetBytes d s n
b)
{-# INLINE _MkSomeNetDir #-}
deriving stock instance (Show n) => Show (SomeNetDir s n)
#if MIN_VERSION_base(4, 16, 0)
instance HasField "unSomeNetDir" (SomeNetDir s n) n where
getField :: SomeNetDir s n -> n
getField (MkSomeNetDir SDirection d
_ (MkNetBytesP n
x)) = n
x
#endif
instance
( k ~ A_Getter,
a ~ n,
b ~ n
) =>
LabelOptic "unSomeNetDir" k (SomeNetDir s n) (SomeNetDir s n) a b
where
labelOptic :: Optic k NoIx (SomeNetDir s n) (SomeNetDir s n) a b
labelOptic = (SomeNetDir s n -> a) -> Getter (SomeNetDir s n) a
forall s a. (s -> a) -> Getter s a
to (\(MkSomeNetDir SDirection d
_ (MkNetBytesP n
x)) -> a
n
x)
{-# INLINE labelOptic #-}
instance
(FromInteger n, Hashable n, MGroup n, SingSize s) =>
Hashable (SomeNetDir s n)
where
hashWithSalt :: Int -> SomeNetDir s n -> Int
hashWithSalt Int
i (MkSomeNetDir SDirection d
d NetBytes d s n
x) =
Int
i Int -> Direction -> Int
forall a. Hashable a => Int -> a -> Int
`hashWithSalt` SDirection d -> Direction
forall (d :: Direction). SDirection d -> Direction
Direction.sdirectionToDirection SDirection d
d Int -> NetBytes d s n -> Int
forall a. Hashable a => Int -> a -> Int
`hashWithSalt` NetBytes d s n
x
instance (NFData n) => NFData (SomeNetDir s n) where
rnf :: SomeNetDir s n -> ()
rnf (MkSomeNetDir SDirection d
d NetBytes d s n
x) = SDirection d
d SDirection d -> () -> ()
forall a b. NFData a => a -> b -> b
`deepseq` NetBytes d s n
x NetBytes d s n -> () -> ()
forall a b. NFData a => a -> b -> b
`deepseq` ()
deriving stock instance Functor (SomeNetDir s)
instance Foldable (SomeNetDir s) where
foldr :: forall a b. (a -> b -> b) -> b -> SomeNetDir s a -> b
foldr a -> b -> b
f b
e (MkSomeNetDir SDirection d
_ (MkNetBytesP a
x)) = a -> b -> b
f a
x b
e
{-# INLINE foldr #-}
instance Traversable (SomeNetDir d) where
traverse :: forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> SomeNetDir d a -> f (SomeNetDir d b)
traverse a -> f b
f (MkSomeNetDir SDirection d
d (MkNetBytesP a
x)) = SDirection d -> NetBytes d d b -> SomeNetDir d b
forall (d :: Direction) (s :: Size) n.
SDirection d -> NetBytes d s n -> SomeNetDir s n
MkSomeNetDir SDirection d
d (NetBytes d d b -> SomeNetDir d b)
-> (b -> NetBytes d d b) -> b -> SomeNetDir d b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. b -> NetBytes d d b
forall (d :: Direction) (s :: Size) n. n -> NetBytes d s n
MkNetBytesP (b -> SomeNetDir d b) -> f b -> f (SomeNetDir d b)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> a -> f b
f a
x
{-# INLINE traverse #-}
sequenceA :: forall (f :: * -> *) a.
Applicative f =>
SomeNetDir d (f a) -> f (SomeNetDir d a)
sequenceA (MkSomeNetDir SDirection d
d (MkNetBytesP f a
x)) = SDirection d -> NetBytes d d a -> SomeNetDir d a
forall (d :: Direction) (s :: Size) n.
SDirection d -> NetBytes d s n -> SomeNetDir s n
MkSomeNetDir SDirection d
d (NetBytes d d a -> SomeNetDir d a)
-> (a -> NetBytes d d a) -> a -> SomeNetDir d a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> NetBytes d d a
forall (d :: Direction) (s :: Size) n. n -> NetBytes d s n
MkNetBytesP (a -> SomeNetDir d a) -> f a -> f (SomeNetDir d a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> f a
x
{-# INLINE sequenceA #-}
instance (Eq n, FromInteger n, SingSize s) => Eq (SomeNetDir s n) where
MkSomeNetDir SDirection d
dx NetBytes d s n
x == :: SomeNetDir s n -> SomeNetDir s n -> Bool
== MkSomeNetDir SDirection d
dy NetBytes d s n
y =
case (SDirection d
dx, SDirection d
dy) of
(SDirection d
SDown, SDirection d
SDown) -> NetBytes d s n
x NetBytes d s n -> NetBytes d s n -> Bool
forall a. Eq a => a -> a -> Bool
== NetBytes d s n
NetBytes d s n
y
(SDirection d
SUp, SDirection d
SUp) -> NetBytes d s n
x NetBytes d s n -> NetBytes d s n -> Bool
forall a. Eq a => a -> a -> Bool
== NetBytes d s n
NetBytes d s n
y
(SDirection d, SDirection d)
_ -> Bool
False
{-# INLINEABLE (==) #-}
instance (MSemigroup n) => MSemiSpace (SomeNetDir s n) n where
MkSomeNetDir SDirection d
dx NetBytes d s n
x .* :: SomeNetDir s n -> n -> SomeNetDir s n
.* n
k = SDirection d -> NetBytes d s n -> SomeNetDir s n
forall (d :: Direction) (s :: Size) n.
SDirection d -> NetBytes d s n -> SomeNetDir s n
MkSomeNetDir SDirection d
dx (NetBytes d s n
x NetBytes d s n -> n -> NetBytes d s n
forall m r. MSemiSpace m r => m -> r -> m
.* n
k)
{-# INLINE (.*) #-}
instance (MGroup n) => MSpace (SomeNetDir s n) n where
MkSomeNetDir SDirection d
dx NetBytes d s n
x .% :: SomeNetDir s n -> n -> SomeNetDir s n
.% n
k = SDirection d -> NetBytes d s n -> SomeNetDir s n
forall (d :: Direction) (s :: Size) n.
SDirection d -> NetBytes d s n -> SomeNetDir s n
MkSomeNetDir SDirection d
dx (NetBytes d s n
x NetBytes d s n -> n -> NetBytes d s n
forall v k. MSpace v k => v -> k -> v
.% n
k)
{-# INLINEABLE (.%) #-}
instance (Normed n) => Normed (SomeNetDir s n) where
norm :: SomeNetDir s n -> SomeNetDir s n
norm (MkSomeNetDir SDirection d
dx NetBytes d s n
x) = SDirection d -> NetBytes d s n -> SomeNetDir s n
forall (d :: Direction) (s :: Size) n.
SDirection d -> NetBytes d s n -> SomeNetDir s n
MkSomeNetDir SDirection d
dx (NetBytes d s n -> NetBytes d s n
forall s. Normed s => s -> s
norm NetBytes d s n
x)
{-# INLINE norm #-}
instance (FromInteger n, MGroup n, SingSize s) => Conversion (SomeNetDir s n) where
type Converted t (SomeNetDir s n) = SomeNetDir t n
convert_ :: forall t. (SingSize t) => SomeNetDir s n -> SomeNetDir t n
convert_ :: forall (t :: Size). SingSize t => SomeNetDir s n -> SomeNetDir t n
convert_ (MkSomeNetDir SDirection d
dir NetBytes d s n
x) = SDirection d -> NetBytes d t n -> SomeNetDir t n
forall (d :: Direction) (s :: Size) n.
SDirection d -> NetBytes d s n -> SomeNetDir s n
MkSomeNetDir SDirection d
dir (NetBytes d t n -> SomeNetDir t n)
-> NetBytes d t n -> SomeNetDir t n
forall a b. (a -> b) -> a -> b
$ NetBytes d s n -> Converted t (NetBytes d s n)
forall a (t :: Size).
(Conversion a, SingSize t) =>
a -> Converted t a
forall (t :: Size).
SingSize t =>
NetBytes d s n -> Converted t (NetBytes d s n)
convert_ NetBytes d s n
x
instance (FromInteger n, MGroup n, Normed n, Ord n, SingSize s) => Normalize (SomeNetDir s n) where
type Norm (SomeNetDir s n) = SomeNet n
normalize :: SomeNetDir s n -> Norm (SomeNetDir s n)
normalize (MkSomeNetDir SDirection d
dir NetBytes d s n
x) =
case NetBytes d s n -> Norm (NetBytes d s n)
forall a. Normalize a => a -> Norm a
normalize NetBytes d s n
x of
MkSomeNetSize SSize s
sz NetBytes d s n
y -> SDirection d -> SSize s -> NetBytes d s n -> SomeNet n
forall (d :: Direction) (s :: Size) n.
SDirection d -> SSize s -> NetBytes d s n -> SomeNet n
MkSomeNet SDirection d
dir SSize s
sz NetBytes d s n
y
{-# INLINEABLE normalize #-}
instance (SingSize s) => Sized (SomeNetDir s n) where
type HideSize (SomeNetDir s n) = SomeNet n
sizeOf :: SomeNetDir s n -> Size
sizeOf = SSize s -> Size
forall (s :: Size). SSize s -> Size
Size.ssizeToSize (SSize s -> Size)
-> (SomeNetDir s n -> SSize s) -> SomeNetDir s n -> Size
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SomeNetDir s n -> SSize s
forall (s :: Size) n. SingSize s => SomeNetDir s n -> SSize s
someNetDirToSSize
{-# INLINE sizeOf #-}
hideSize :: SomeNetDir s n -> HideSize (SomeNetDir s n)
hideSize (MkSomeNetDir SDirection d
d NetBytes d s n
b) = SDirection d -> SSize s -> NetBytes d s n -> SomeNet n
forall (d :: Direction) (s :: Size) n.
SDirection d -> SSize s -> NetBytes d s n -> SomeNet n
MkSomeNet SDirection d
d (forall (s :: Size). SingSize s => SSize s
singSize @s) NetBytes d s n
b
{-# INLINE hideSize #-}
instance Directed (SomeNetDir s n) where
type HideDirection (SomeNetDir s n) = SomeNetDir s n
directionOf :: SomeNetDir s n -> Direction
directionOf (MkSomeNetDir SDirection d
d NetBytes d s n
_) = SDirection d -> Direction
forall (d :: Direction). SDirection d -> Direction
Direction.sdirectionToDirection SDirection d
d
{-# INLINE directionOf #-}
hideDirection :: SomeNetDir s n -> HideDirection (SomeNetDir s n)
hideDirection = SomeNetDir s n -> HideDirection (SomeNetDir s n)
SomeNetDir s n -> SomeNetDir s n
forall a. a -> a
id
{-# INLINE hideDirection #-}
instance RawNumeric (SomeNetDir s n) where
type Raw (SomeNetDir s n) = n
toRaw :: SomeNetDir s n -> Raw (SomeNetDir s n)
toRaw (MkSomeNetDir SDirection d
_ NetBytes d s n
b) = NetBytes d s n -> Raw (NetBytes d s n)
forall a. RawNumeric a => a -> Raw a
toRaw NetBytes d s n
b
{-# INLINE toRaw #-}
instance (Read n) => Parser (SomeNetDir s n) where
parser :: Parsec Void Text (SomeNetDir s n)
parser = do
n
bytes <- ParsecT Void Text Identity n
forall n. Read n => Parsec Void Text n
Parser.parseDigits
ParsecT Void Text Identity ()
forall e s (m :: * -> *).
(MonadParsec e s m, Token s ~ Char) =>
m ()
MPC.space
Direction
dir <- ParsecT Void Text Identity Direction
forall a. Parser a => Parsec Void Text a
parser
ParsecT Void Text Identity ()
forall e s (m :: * -> *).
(MonadParsec e s m, Token s ~ Char) =>
m ()
MPC.space
ParsecT Void Text Identity ()
forall e s (m :: * -> *). MonadParsec e s m => m ()
MP.eof
pure $ case Direction
dir of
Direction
Down -> SDirection 'Down -> NetBytes 'Down s n -> SomeNetDir s n
forall (d :: Direction) (s :: Size) n.
SDirection d -> NetBytes d s n -> SomeNetDir s n
MkSomeNetDir SDirection 'Down
SDown (NetBytes 'Down s n -> SomeNetDir s n)
-> NetBytes 'Down s n -> SomeNetDir s n
forall a b. (a -> b) -> a -> b
$ n -> NetBytes 'Down s n
forall (d :: Direction) (s :: Size) n. n -> NetBytes d s n
MkNetBytesP n
bytes
Direction
Up -> SDirection 'Up -> NetBytes 'Up s n -> SomeNetDir s n
forall (d :: Direction) (s :: Size) n.
SDirection d -> NetBytes d s n -> SomeNetDir s n
MkSomeNetDir SDirection 'Up
SUp (NetBytes 'Up s n -> SomeNetDir s n)
-> NetBytes 'Up s n -> SomeNetDir s n
forall a b. (a -> b) -> a -> b
$ n -> NetBytes 'Up s n
forall (d :: Direction) (s :: Size) n. n -> NetBytes d s n
MkNetBytesP n
bytes
{-# INLINEABLE parser #-}
type SomeNet :: Type -> Type
data SomeNet (n :: Type) where
MkSomeNet :: SDirection d -> SSize s -> NetBytes d s n -> SomeNet n
_MkSomeNet :: forall s d n. (SingDirection d, SingSize s) => Review (SomeNet n) (NetBytes d s n)
_MkSomeNet :: forall (s :: Size) (d :: Direction) n.
(SingDirection d, SingSize s) =>
Review (SomeNet n) (NetBytes d s n)
_MkSomeNet = (NetBytes d s n -> SomeNet n)
-> Review (SomeNet n) (NetBytes d s n)
forall b t. (b -> t) -> Review t b
unto (\NetBytes d s n
b -> SDirection d -> SSize s -> NetBytes d s n -> SomeNet n
forall (d :: Direction) (s :: Size) n.
SDirection d -> SSize s -> NetBytes d s n -> SomeNet n
MkSomeNet (NetBytes d s n -> SDirection d
forall (d :: Direction) (s :: Size) n.
SingDirection d =>
NetBytes d s n -> SDirection d
netToSDirection NetBytes d s n
b) (NetBytes d s n -> SSize s
forall (s :: Size) (d :: Direction) n.
SingSize s =>
NetBytes d s n -> SSize s
netToSSize NetBytes d s n
b) NetBytes d s n
b)
{-# INLINE _MkSomeNet #-}
deriving stock instance (Show n) => Show (SomeNet n)
#if MIN_VERSION_base(4, 16, 0)
instance HasField "unSomeNet" (SomeNet n) n where
getField :: SomeNet n -> n
getField (MkSomeNet SDirection d
_ SSize s
_ (MkNetBytesP n
x)) = n
x
#endif
instance
( k ~ A_Getter,
a ~ n,
b ~ n
) =>
LabelOptic "unSomeNet" k (SomeNet n) (SomeNet n) a b
where
labelOptic :: Optic k NoIx (SomeNet n) (SomeNet n) a b
labelOptic = (SomeNet n -> a) -> Getter (SomeNet n) a
forall s a. (s -> a) -> Getter s a
to (\(MkSomeNet SDirection d
_ SSize s
_ (MkNetBytesP n
x)) -> a
n
x)
{-# INLINE labelOptic #-}
instance (FromInteger n, Hashable n, MGroup n) => Hashable (SomeNet n) where
hashWithSalt :: Int -> SomeNet n -> Int
hashWithSalt Int
i (MkSomeNet SDirection d
d SSize s
s NetBytes d s n
x) =
Int
i
Int -> Direction -> Int
forall a. Hashable a => Int -> a -> Int
`hashWithSalt` SDirection d -> Direction
forall (d :: Direction). SDirection d -> Direction
Direction.sdirectionToDirection SDirection d
d
Int -> Size -> Int
forall a. Hashable a => Int -> a -> Int
`hashWithSalt` SSize s -> Size
forall (s :: Size). SSize s -> Size
Size.ssizeToSize SSize s
s
Int -> NetBytes d s n -> Int
forall a. Hashable a => Int -> a -> Int
`hashWithSalt` NetBytes d s n
x
instance (NFData n) => NFData (SomeNet n) where
rnf :: SomeNet n -> ()
rnf (MkSomeNet SDirection d
d SSize s
s NetBytes d s n
x) = SDirection d
d SDirection d -> () -> ()
forall a b. NFData a => a -> b -> b
`deepseq` SSize s
s SSize s -> () -> ()
forall a b. NFData a => a -> b -> b
`deepseq` NetBytes d s n
x NetBytes d s n -> () -> ()
forall a b. NFData a => a -> b -> b
`deepseq` ()
deriving stock instance Functor SomeNet
instance Foldable SomeNet where
foldr :: forall a b. (a -> b -> b) -> b -> SomeNet a -> b
foldr a -> b -> b
f b
e (MkSomeNet SDirection d
_ SSize s
_ (MkNetBytesP a
x)) = a -> b -> b
f a
x b
e
{-# INLINE foldr #-}
instance Traversable SomeNet where
traverse :: forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> SomeNet a -> f (SomeNet b)
traverse a -> f b
f (MkSomeNet SDirection d
d SSize s
sz (MkNetBytesP a
x)) = SDirection d -> SSize s -> NetBytes d s b -> SomeNet b
forall (d :: Direction) (s :: Size) n.
SDirection d -> SSize s -> NetBytes d s n -> SomeNet n
MkSomeNet SDirection d
d SSize s
sz (NetBytes d s b -> SomeNet b)
-> (b -> NetBytes d s b) -> b -> SomeNet b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. b -> NetBytes d s b
forall (d :: Direction) (s :: Size) n. n -> NetBytes d s n
MkNetBytesP (b -> SomeNet b) -> f b -> f (SomeNet b)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> a -> f b
f a
x
{-# INLINE traverse #-}
sequenceA :: forall (f :: * -> *) a.
Applicative f =>
SomeNet (f a) -> f (SomeNet a)
sequenceA (MkSomeNet SDirection d
d SSize s
sz (MkNetBytesP f a
x)) = SDirection d -> SSize s -> NetBytes d s a -> SomeNet a
forall (d :: Direction) (s :: Size) n.
SDirection d -> SSize s -> NetBytes d s n -> SomeNet n
MkSomeNet SDirection d
d SSize s
sz (NetBytes d s a -> SomeNet a)
-> (a -> NetBytes d s a) -> a -> SomeNet a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> NetBytes d s a
forall (d :: Direction) (s :: Size) n. n -> NetBytes d s n
MkNetBytesP (a -> SomeNet a) -> f a -> f (SomeNet a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> f a
x
{-# INLINE sequenceA #-}
instance (Eq n, FromInteger n, MGroup n) => Eq (SomeNet n) where
MkSomeNet SDirection d
dx SSize s
szx NetBytes d s n
x == :: SomeNet n -> SomeNet n -> Bool
== MkSomeNet SDirection d
dy SSize s
szy NetBytes d s n
y =
SSize s -> (SingSize s => Bool) -> Bool
forall (s :: Size) r. SSize s -> (SingSize s => r) -> r
Size.withSingSize SSize s
szx ((SingSize s => Bool) -> Bool) -> (SingSize s => Bool) -> Bool
forall a b. (a -> b) -> a -> b
$
SSize s -> (SingSize s => Bool) -> Bool
forall (s :: Size) r. SSize s -> (SingSize s => r) -> r
Size.withSingSize SSize s
szy ((SingSize s => Bool) -> Bool) -> (SingSize s => Bool) -> Bool
forall a b. (a -> b) -> a -> b
$
case (SDirection d
dx, SDirection d
dy) of
(SDirection d
SDown, SDirection d
SDown) -> forall a (t :: Size).
(Conversion a, SingSize t) =>
a -> Converted t a
convert_ @_ @B NetBytes d s n
x NetBytes 'Down 'B n -> NetBytes 'Down 'B n -> Bool
forall a. Eq a => a -> a -> Bool
== NetBytes d s n -> Converted 'B (NetBytes d s n)
forall a (t :: Size).
(Conversion a, SingSize t) =>
a -> Converted t a
forall (t :: Size).
SingSize t =>
NetBytes d s n -> Converted t (NetBytes d s n)
convert_ NetBytes d s n
y
(SDirection d
SUp, SDirection d
SUp) -> forall a (t :: Size).
(Conversion a, SingSize t) =>
a -> Converted t a
convert_ @_ @B NetBytes d s n
x NetBytes 'Up 'B n -> NetBytes 'Up 'B n -> Bool
forall a. Eq a => a -> a -> Bool
== NetBytes d s n -> Converted 'B (NetBytes d s n)
forall a (t :: Size).
(Conversion a, SingSize t) =>
a -> Converted t a
forall (t :: Size).
SingSize t =>
NetBytes d s n -> Converted t (NetBytes d s n)
convert_ NetBytes d s n
y
(SDirection d, SDirection d)
_ -> Bool
False
{-# INLINEABLE (==) #-}
instance (MSemigroup n) => MSemiSpace (SomeNet n) n where
MkSomeNet SDirection d
d SSize s
s NetBytes d s n
x .* :: SomeNet n -> n -> SomeNet n
.* n
k = SDirection d -> SSize s -> NetBytes d s n -> SomeNet n
forall (d :: Direction) (s :: Size) n.
SDirection d -> SSize s -> NetBytes d s n -> SomeNet n
MkSomeNet SDirection d
d SSize s
s (NetBytes d s n
x NetBytes d s n -> n -> NetBytes d s n
forall m r. MSemiSpace m r => m -> r -> m
.* n
k)
{-# INLINE (.*) #-}
instance (MGroup n) => MSpace (SomeNet n) n where
MkSomeNet SDirection d
d SSize s
s NetBytes d s n
x .% :: SomeNet n -> n -> SomeNet n
.% n
k = SDirection d -> SSize s -> NetBytes d s n -> SomeNet n
forall (d :: Direction) (s :: Size) n.
SDirection d -> SSize s -> NetBytes d s n -> SomeNet n
MkSomeNet SDirection d
d SSize s
s (NetBytes d s n
x NetBytes d s n -> n -> NetBytes d s n
forall v k. MSpace v k => v -> k -> v
.% n
k)
{-# INLINEABLE (.%) #-}
instance (Normed n) => Normed (SomeNet n) where
norm :: SomeNet n -> SomeNet n
norm (MkSomeNet SDirection d
d SSize s
s NetBytes d s n
x) = SDirection d -> SSize s -> NetBytes d s n -> SomeNet n
forall (d :: Direction) (s :: Size) n.
SDirection d -> SSize s -> NetBytes d s n -> SomeNet n
MkSomeNet SDirection d
d SSize s
s (NetBytes d s n -> NetBytes d s n
forall s. Normed s => s -> s
norm NetBytes d s n
x)
{-# INLINE norm #-}
instance (FromInteger n, MGroup n) => Conversion (SomeNet n) where
type Converted t (SomeNet n) = SomeNetDir t n
convert_ :: forall t. (SingSize t) => SomeNet n -> SomeNetDir t n
convert_ :: forall (t :: Size). SingSize t => SomeNet n -> SomeNetDir t n
convert_ (MkSomeNet SDirection d
dir SSize s
sz NetBytes d s n
x) = SSize s -> (SingSize s => SomeNetDir t n) -> SomeNetDir t n
forall (s :: Size) r. SSize s -> (SingSize s => r) -> r
Size.withSingSize SSize s
sz ((SingSize s => SomeNetDir t n) -> SomeNetDir t n)
-> (SingSize s => SomeNetDir t n) -> SomeNetDir t n
forall a b. (a -> b) -> a -> b
$ SDirection d -> NetBytes d t n -> SomeNetDir t n
forall (d :: Direction) (s :: Size) n.
SDirection d -> NetBytes d s n -> SomeNetDir s n
MkSomeNetDir SDirection d
dir (NetBytes d t n -> SomeNetDir t n)
-> NetBytes d t n -> SomeNetDir t n
forall a b. (a -> b) -> a -> b
$ NetBytes d s n -> Converted t (NetBytes d s n)
forall a (t :: Size).
(Conversion a, SingSize t) =>
a -> Converted t a
forall (t :: Size).
SingSize t =>
NetBytes d s n -> Converted t (NetBytes d s n)
convert_ NetBytes d s n
x
instance (FromInteger n, MGroup n, Normed n, Ord n) => Normalize (SomeNet n) where
type Norm (SomeNet n) = SomeNet n
normalize :: SomeNet n -> Norm (SomeNet n)
normalize (MkSomeNet SDirection d
dir SSize s
sz NetBytes d s n
x) =
case SSize s
-> (SingSize s => NetBytes d s n -> SomeNetSize d n)
-> NetBytes d s n
-> SomeNetSize d n
forall (s :: Size) r. SSize s -> (SingSize s => r) -> r
Size.withSingSize SSize s
sz SingSize s => NetBytes d s n -> SomeNetSize d n
NetBytes d s n -> Norm (NetBytes d s n)
NetBytes d s n -> SomeNetSize d n
forall a. Normalize a => a -> Norm a
normalize NetBytes d s n
x of
MkSomeNetSize SSize s
sz' NetBytes d s n
x' -> SDirection d -> SSize s -> NetBytes d s n -> SomeNet n
forall (d :: Direction) (s :: Size) n.
SDirection d -> SSize s -> NetBytes d s n -> SomeNet n
MkSomeNet SDirection d
dir SSize s
sz' NetBytes d s n
x'
{-# INLINEABLE normalize #-}
instance Sized (SomeNet n) where
type HideSize (SomeNet n) = SomeNet n
sizeOf :: SomeNet n -> Size
sizeOf (MkSomeNet SDirection d
_ SSize s
sz NetBytes d s n
_) = SSize s -> Size
forall (s :: Size). SSize s -> Size
Size.ssizeToSize SSize s
sz
{-# INLINE sizeOf #-}
hideSize :: SomeNet n -> HideSize (SomeNet n)
hideSize = SomeNet n -> HideSize (SomeNet n)
SomeNet n -> SomeNet n
forall a. a -> a
id
{-# INLINE hideSize #-}
instance Directed (SomeNet n) where
type HideDirection (SomeNet n) = SomeNet n
directionOf :: SomeNet n -> Direction
directionOf (MkSomeNet SDirection d
d SSize s
_ NetBytes d s n
_) = SDirection d -> Direction
forall (d :: Direction). SDirection d -> Direction
Direction.sdirectionToDirection SDirection d
d
{-# INLINE directionOf #-}
hideDirection :: SomeNet n -> HideDirection (SomeNet n)
hideDirection = SomeNet n -> HideDirection (SomeNet n)
SomeNet n -> SomeNet n
forall a. a -> a
id
{-# INLINE hideDirection #-}
instance RawNumeric (SomeNet n) where
type Raw (SomeNet n) = n
toRaw :: SomeNet n -> Raw (SomeNet n)
toRaw (MkSomeNet SDirection d
_ SSize s
_ NetBytes d s n
b) = NetBytes d s n -> Raw (NetBytes d s n)
forall a. RawNumeric a => a -> Raw a
toRaw NetBytes d s n
b
{-# INLINE toRaw #-}
instance (Read n) => Parser (SomeNet n) where
parser :: Parsec Void Text (SomeNet n)
parser = do
n
bytes <- ParsecT Void Text Identity n
forall n. Read n => Parsec Void Text n
Parser.parseDigits
ParsecT Void Text Identity ()
forall e s (m :: * -> *).
(MonadParsec e s m, Token s ~ Char) =>
m ()
MPC.space
Size
size <- ParsecT Void Text Identity Size
forall a. Parser a => Parsec Void Text a
parser
ParsecT Void Text Identity ()
forall e s (m :: * -> *).
(MonadParsec e s m, Token s ~ Char) =>
m ()
MPC.space1
Direction
dir <- ParsecT Void Text Identity Direction
forall a. Parser a => Parsec Void Text a
parser
ParsecT Void Text Identity ()
forall e s (m :: * -> *).
(MonadParsec e s m, Token s ~ Char) =>
m ()
MPC.space
ParsecT Void Text Identity ()
forall e s (m :: * -> *). MonadParsec e s m => m ()
MP.eof
pure $ case Direction
dir of
Direction
Down -> case Size
size of
Size
B -> SDirection 'Down -> SSize 'B -> NetBytes 'Down 'B n -> SomeNet n
forall (d :: Direction) (s :: Size) n.
SDirection d -> SSize s -> NetBytes d s n -> SomeNet n
MkSomeNet SDirection 'Down
SDown SSize 'B
SB (NetBytes 'Down 'B n -> SomeNet n)
-> NetBytes 'Down 'B n -> SomeNet n
forall a b. (a -> b) -> a -> b
$ n -> NetBytes 'Down 'B n
forall (d :: Direction) (s :: Size) n. n -> NetBytes d s n
MkNetBytesP n
bytes
Size
K -> SDirection 'Down -> SSize 'K -> NetBytes 'Down 'K n -> SomeNet n
forall (d :: Direction) (s :: Size) n.
SDirection d -> SSize s -> NetBytes d s n -> SomeNet n
MkSomeNet SDirection 'Down
SDown SSize 'K
SK (NetBytes 'Down 'K n -> SomeNet n)
-> NetBytes 'Down 'K n -> SomeNet n
forall a b. (a -> b) -> a -> b
$ n -> NetBytes 'Down 'K n
forall (d :: Direction) (s :: Size) n. n -> NetBytes d s n
MkNetBytesP n
bytes
Size
M -> SDirection 'Down -> SSize 'M -> NetBytes 'Down 'M n -> SomeNet n
forall (d :: Direction) (s :: Size) n.
SDirection d -> SSize s -> NetBytes d s n -> SomeNet n
MkSomeNet SDirection 'Down
SDown SSize 'M
SM (NetBytes 'Down 'M n -> SomeNet n)
-> NetBytes 'Down 'M n -> SomeNet n
forall a b. (a -> b) -> a -> b
$ n -> NetBytes 'Down 'M n
forall (d :: Direction) (s :: Size) n. n -> NetBytes d s n
MkNetBytesP n
bytes
Size
G -> SDirection 'Down -> SSize 'G -> NetBytes 'Down 'G n -> SomeNet n
forall (d :: Direction) (s :: Size) n.
SDirection d -> SSize s -> NetBytes d s n -> SomeNet n
MkSomeNet SDirection 'Down
SDown SSize 'G
SG (NetBytes 'Down 'G n -> SomeNet n)
-> NetBytes 'Down 'G n -> SomeNet n
forall a b. (a -> b) -> a -> b
$ n -> NetBytes 'Down 'G n
forall (d :: Direction) (s :: Size) n. n -> NetBytes d s n
MkNetBytesP n
bytes
Size
T -> SDirection 'Down -> SSize 'T -> NetBytes 'Down 'T n -> SomeNet n
forall (d :: Direction) (s :: Size) n.
SDirection d -> SSize s -> NetBytes d s n -> SomeNet n
MkSomeNet SDirection 'Down
SDown SSize 'T
ST (NetBytes 'Down 'T n -> SomeNet n)
-> NetBytes 'Down 'T n -> SomeNet n
forall a b. (a -> b) -> a -> b
$ n -> NetBytes 'Down 'T n
forall (d :: Direction) (s :: Size) n. n -> NetBytes d s n
MkNetBytesP n
bytes
Size
P -> SDirection 'Down -> SSize 'P -> NetBytes 'Down 'P n -> SomeNet n
forall (d :: Direction) (s :: Size) n.
SDirection d -> SSize s -> NetBytes d s n -> SomeNet n
MkSomeNet SDirection 'Down
SDown SSize 'P
SP (NetBytes 'Down 'P n -> SomeNet n)
-> NetBytes 'Down 'P n -> SomeNet n
forall a b. (a -> b) -> a -> b
$ n -> NetBytes 'Down 'P n
forall (d :: Direction) (s :: Size) n. n -> NetBytes d s n
MkNetBytesP n
bytes
Size
E -> SDirection 'Down -> SSize 'E -> NetBytes 'Down 'E n -> SomeNet n
forall (d :: Direction) (s :: Size) n.
SDirection d -> SSize s -> NetBytes d s n -> SomeNet n
MkSomeNet SDirection 'Down
SDown SSize 'E
SE (NetBytes 'Down 'E n -> SomeNet n)
-> NetBytes 'Down 'E n -> SomeNet n
forall a b. (a -> b) -> a -> b
$ n -> NetBytes 'Down 'E n
forall (d :: Direction) (s :: Size) n. n -> NetBytes d s n
MkNetBytesP n
bytes
Size
Z -> SDirection 'Down -> SSize 'Z -> NetBytes 'Down 'Z n -> SomeNet n
forall (d :: Direction) (s :: Size) n.
SDirection d -> SSize s -> NetBytes d s n -> SomeNet n
MkSomeNet SDirection 'Down
SDown SSize 'Z
SZ (NetBytes 'Down 'Z n -> SomeNet n)
-> NetBytes 'Down 'Z n -> SomeNet n
forall a b. (a -> b) -> a -> b
$ n -> NetBytes 'Down 'Z n
forall (d :: Direction) (s :: Size) n. n -> NetBytes d s n
MkNetBytesP n
bytes
Size
Y -> SDirection 'Down -> SSize 'Y -> NetBytes 'Down 'Y n -> SomeNet n
forall (d :: Direction) (s :: Size) n.
SDirection d -> SSize s -> NetBytes d s n -> SomeNet n
MkSomeNet SDirection 'Down
SDown SSize 'Y
SY (NetBytes 'Down 'Y n -> SomeNet n)
-> NetBytes 'Down 'Y n -> SomeNet n
forall a b. (a -> b) -> a -> b
$ n -> NetBytes 'Down 'Y n
forall (d :: Direction) (s :: Size) n. n -> NetBytes d s n
MkNetBytesP n
bytes
Direction
Up -> case Size
size of
Size
B -> SDirection 'Up -> SSize 'B -> NetBytes 'Up 'B n -> SomeNet n
forall (d :: Direction) (s :: Size) n.
SDirection d -> SSize s -> NetBytes d s n -> SomeNet n
MkSomeNet SDirection 'Up
SUp SSize 'B
SB (NetBytes 'Up 'B n -> SomeNet n) -> NetBytes 'Up 'B n -> SomeNet n
forall a b. (a -> b) -> a -> b
$ n -> NetBytes 'Up 'B n
forall (d :: Direction) (s :: Size) n. n -> NetBytes d s n
MkNetBytesP n
bytes
Size
K -> SDirection 'Up -> SSize 'K -> NetBytes 'Up 'K n -> SomeNet n
forall (d :: Direction) (s :: Size) n.
SDirection d -> SSize s -> NetBytes d s n -> SomeNet n
MkSomeNet SDirection 'Up
SUp SSize 'K
SK (NetBytes 'Up 'K n -> SomeNet n) -> NetBytes 'Up 'K n -> SomeNet n
forall a b. (a -> b) -> a -> b
$ n -> NetBytes 'Up 'K n
forall (d :: Direction) (s :: Size) n. n -> NetBytes d s n
MkNetBytesP n
bytes
Size
M -> SDirection 'Up -> SSize 'M -> NetBytes 'Up 'M n -> SomeNet n
forall (d :: Direction) (s :: Size) n.
SDirection d -> SSize s -> NetBytes d s n -> SomeNet n
MkSomeNet SDirection 'Up
SUp SSize 'M
SM (NetBytes 'Up 'M n -> SomeNet n) -> NetBytes 'Up 'M n -> SomeNet n
forall a b. (a -> b) -> a -> b
$ n -> NetBytes 'Up 'M n
forall (d :: Direction) (s :: Size) n. n -> NetBytes d s n
MkNetBytesP n
bytes
Size
G -> SDirection 'Up -> SSize 'G -> NetBytes 'Up 'G n -> SomeNet n
forall (d :: Direction) (s :: Size) n.
SDirection d -> SSize s -> NetBytes d s n -> SomeNet n
MkSomeNet SDirection 'Up
SUp SSize 'G
SG (NetBytes 'Up 'G n -> SomeNet n) -> NetBytes 'Up 'G n -> SomeNet n
forall a b. (a -> b) -> a -> b
$ n -> NetBytes 'Up 'G n
forall (d :: Direction) (s :: Size) n. n -> NetBytes d s n
MkNetBytesP n
bytes
Size
T -> SDirection 'Up -> SSize 'T -> NetBytes 'Up 'T n -> SomeNet n
forall (d :: Direction) (s :: Size) n.
SDirection d -> SSize s -> NetBytes d s n -> SomeNet n
MkSomeNet SDirection 'Up
SUp SSize 'T
ST (NetBytes 'Up 'T n -> SomeNet n) -> NetBytes 'Up 'T n -> SomeNet n
forall a b. (a -> b) -> a -> b
$ n -> NetBytes 'Up 'T n
forall (d :: Direction) (s :: Size) n. n -> NetBytes d s n
MkNetBytesP n
bytes
Size
P -> SDirection 'Up -> SSize 'P -> NetBytes 'Up 'P n -> SomeNet n
forall (d :: Direction) (s :: Size) n.
SDirection d -> SSize s -> NetBytes d s n -> SomeNet n
MkSomeNet SDirection 'Up
SUp SSize 'P
SP (NetBytes 'Up 'P n -> SomeNet n) -> NetBytes 'Up 'P n -> SomeNet n
forall a b. (a -> b) -> a -> b
$ n -> NetBytes 'Up 'P n
forall (d :: Direction) (s :: Size) n. n -> NetBytes d s n
MkNetBytesP n
bytes
Size
E -> SDirection 'Up -> SSize 'E -> NetBytes 'Up 'E n -> SomeNet n
forall (d :: Direction) (s :: Size) n.
SDirection d -> SSize s -> NetBytes d s n -> SomeNet n
MkSomeNet SDirection 'Up
SUp SSize 'E
SE (NetBytes 'Up 'E n -> SomeNet n) -> NetBytes 'Up 'E n -> SomeNet n
forall a b. (a -> b) -> a -> b
$ n -> NetBytes 'Up 'E n
forall (d :: Direction) (s :: Size) n. n -> NetBytes d s n
MkNetBytesP n
bytes
Size
Z -> SDirection 'Up -> SSize 'Z -> NetBytes 'Up 'Z n -> SomeNet n
forall (d :: Direction) (s :: Size) n.
SDirection d -> SSize s -> NetBytes d s n -> SomeNet n
MkSomeNet SDirection 'Up
SUp SSize 'Z
SZ (NetBytes 'Up 'Z n -> SomeNet n) -> NetBytes 'Up 'Z n -> SomeNet n
forall a b. (a -> b) -> a -> b
$ n -> NetBytes 'Up 'Z n
forall (d :: Direction) (s :: Size) n. n -> NetBytes d s n
MkNetBytesP n
bytes
Size
Y -> SDirection 'Up -> SSize 'Y -> NetBytes 'Up 'Y n -> SomeNet n
forall (d :: Direction) (s :: Size) n.
SDirection d -> SSize s -> NetBytes d s n -> SomeNet n
MkSomeNet SDirection 'Up
SUp SSize 'Y
SY (NetBytes 'Up 'Y n -> SomeNet n) -> NetBytes 'Up 'Y n -> SomeNet n
forall a b. (a -> b) -> a -> b
$ n -> NetBytes 'Up 'Y n
forall (d :: Direction) (s :: Size) n. n -> NetBytes d s n
MkNetBytesP n
bytes
{-# INLINEABLE parser #-}