Copyright | (c) Justin Le 2018 |
---|---|
License | BSD3 |
Maintainer | justin@jle.im |
Stability | experimental |
Portability | non-portable |
Safe Haskell | None |
Language | Haskell2010 |
If you are writing a library that needs to export BVar
s of tuples,
consider using the tuples in this module so that your library can have
easy interoperability with other libraries using backprop.
Because of API decisions, backprop
and gradBP
only work with things
with Num
instances. However, this disallows default Prelude
tuples
(without orphan instances from packages like
NumInstances).
Until tuples have Num
instances in base, this module is intended to
be a workaround for situations where:
This comes up often in cases where:
- A function wants to return more than one value (
BVar
s (T2
a b) - You want to uncurry a
BVar
function to use withbackprop
andgradBP
. - You want to use the useful
Prism
s automatically generated by the lens library, which use tuples for multiple-constructor fields.
Only 2-tuples and 3-tuples are provided. Any more and you should probably be using your own custom product types, with instances automatically generated from something like one-liner-instances.
Lenses into the fields are provided, but they also work with _1
, _2
,
and _3
from Lens.Micro. However, note that these are incompatible
with _1
, _2
, and _3
from Control.Lens.
You can "construct" a
with functions like
BVar
s (T2
a b)isoVar
.
Since: 0.1.1.0
Synopsis
- data T0 = T0
- data a :# b = !a :# !b
- pattern (:##) :: (Backprop a, Backprop b, Reifies s W) => BVar s a -> BVar s b -> BVar s (a :# b)
- t2Tup :: (a :# b) -> (a, b)
- tupT2 :: (a, b) -> a :# b
- uncurryT2 :: (a -> b -> c) -> (a :# b) -> c
- curryT2 :: ((a :# b) -> c) -> a -> b -> c
- t2_1 :: Lens (a :# b) (a' :# b) a a'
- t2_2 :: Lens (a :# b) (a :# b') b b'
- type T = Rec TF
- newtype TF a = TF {
- getTF :: a
- pattern (:&&) :: a -> T as -> T (a ': as)
- indexT :: Index as a -> T as -> a
- tOnly :: T '[a] -> a
- onlyT :: a -> T '[a]
- tHead :: Lens (T (a ': as)) (T (b ': as)) a b
- tTail :: Lens (T (a ': as)) (T (a ': bs)) (T as) (T bs)
- type TMaybe = PMaybe TF
- data PMaybe (a :: k -> Type) (b :: Maybe k) :: forall k. (k -> Type) -> Maybe k -> Type where
- fromPJust :: PMaybe f (Just a) -> f a
- type family (a :: Maybe Type) :#? (b :: Maybe Type) :: Maybe Type where ...
- pattern (:#?) :: (AllConstrainedProd Backprop a, AllConstrainedProd Backprop b, Reifies s W, PureProd Maybe a, PureProd Maybe b) => PMaybe (BVar s) a -> PMaybe (BVar s) b -> PMaybe (BVar s) (a :#? b)
- splitTupMaybe :: forall f a b. (PureProd Maybe a, PureProd Maybe b) => (forall a' b'. (a ~ Just a', b ~ Just b') => f (a' :# b') -> (f a', f b')) -> PMaybe f (a :#? b) -> (PMaybe f a, PMaybe f b)
- tupMaybe :: forall f a b. (forall a' b'. (a ~ Just a', b ~ Just b') => f a' -> f b' -> f (a' :# b')) -> PMaybe f a -> PMaybe f b -> PMaybe f (a :#? b)
- pattern MaybB :: (Reifies s W, AllConstrainedProd Backprop a, PureProd Maybe a) => PMaybe (BVar s) a -> BVar s (TMaybe a)
Zero-tuples (unit)
Unit ('()') with Num
, Fractional
, and Floating
instances.
Be aware that the methods in its numerical instances are all non-strict:
_ + _ =T0
negate
_ =T0
fromIntegral
_ =T0
Since: 0.1.4.0
Instances
Eq T0 Source # | |
Floating T0 Source # | |
Defined in Data.Type.Tuple | |
Fractional T0 Source # | |
Data T0 Source # | |
Defined in Data.Type.Tuple gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> T0 -> c T0 # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c T0 # dataTypeOf :: T0 -> DataType # dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c T0) # dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c T0) # gmapT :: (forall b. Data b => b -> b) -> T0 -> T0 # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> T0 -> r # gmapQr :: (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> T0 -> r # gmapQ :: (forall d. Data d => d -> u) -> T0 -> [u] # gmapQi :: Int -> (forall d. Data d => d -> u) -> T0 -> u # gmapM :: Monad m => (forall d. Data d => d -> m d) -> T0 -> m T0 # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> T0 -> m T0 # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> T0 -> m T0 # | |
Num T0 Source # | |
Ord T0 Source # | |
Read T0 Source # | |
Show T0 Source # | |
Generic T0 Source # | |
Semigroup T0 Source # | |
Monoid T0 Source # | |
NFData T0 Source # | |
Defined in Data.Type.Tuple | |
Binary T0 Source # | Since: 0.1.5.1 |
Initialize T0 Source # | |
Defined in Backprop.Learn.Initialize | |
type Rep T0 Source # | |
Two-tuples
Strict 2-tuple with Num
, Fractional
, and Floating
instances.
Since: 0.1.1.0
!a :# !b infixr 1 |
Instances
Bifunctor (:#) Source # | |
(LinearInPlace m c a, LinearInPlace m c b) => LinearInPlace m c (a :# b) Source # | |
(Linear c a, Linear c b) => Linear c (a :# b) Source # | |
(Floating c, Ord c, Metric c a, Metric c b) => Metric c (a :# b) Source # | |
(Mutable m a, Mutable m b) => Mutable m (a :# b) Source # | |
Defined in Data.Type.Tuple thawRef :: (a :# b) -> m (Ref m (a :# b)) # freezeRef :: Ref m (a :# b) -> m (a :# b) # copyRef :: Ref m (a :# b) -> (a :# b) -> m () # modifyRef :: Ref m (a :# b) -> ((a :# b) -> a :# b) -> m () # modifyRef' :: Ref m (a :# b) -> ((a :# b) -> a :# b) -> m () # updateRef :: Ref m (a :# b) -> ((a :# b) -> (a :# b, b0)) -> m b0 # updateRef' :: Ref m (a :# b) -> ((a :# b) -> (a :# b, b0)) -> m b0 # | |
(Initialize a, Initialize b, Regularize a, Regularize b, Binary a, Binary b, NFData a, NFData b, LinearInPlace m Double a, LinearInPlace m Double b) => Learnable m (a :# b) Source # | |
Defined in Backprop.Learn.Model.Types | |
Functor ((:#) a) Source # | |
(Eq a, Eq b) => Eq (a :# b) Source # | |
(Floating a, Floating b) => Floating (a :# b) Source # | |
(Fractional a, Fractional b) => Fractional (a :# b) Source # | |
(Data a, Data b) => Data (a :# b) Source # | |
Defined in Data.Type.Tuple gfoldl :: (forall d b0. Data d => c (d -> b0) -> d -> c b0) -> (forall g. g -> c g) -> (a :# b) -> c (a :# b) # gunfold :: (forall b0 r. Data b0 => c (b0 -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c (a :# b) # toConstr :: (a :# b) -> Constr # dataTypeOf :: (a :# b) -> DataType # dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c (a :# b)) # dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (a :# b)) # gmapT :: (forall b0. Data b0 => b0 -> b0) -> (a :# b) -> a :# b # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> (a :# b) -> r # gmapQr :: (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> (a :# b) -> r # gmapQ :: (forall d. Data d => d -> u) -> (a :# b) -> [u] # gmapQi :: Int -> (forall d. Data d => d -> u) -> (a :# b) -> u # gmapM :: Monad m => (forall d. Data d => d -> m d) -> (a :# b) -> m (a :# b) # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> (a :# b) -> m (a :# b) # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> (a :# b) -> m (a :# b) # | |
(Num a, Num b) => Num (a :# b) Source # | |
(Ord a, Ord b) => Ord (a :# b) Source # | |
Defined in Data.Type.Tuple | |
(Read a, Read b) => Read (a :# b) Source # | |
(Show a, Show b) => Show (a :# b) Source # | |
Generic (a :# b) Source # | |
(Semigroup a, Semigroup b) => Semigroup (a :# b) Source # | |
(Semigroup a, Semigroup b, Monoid a, Monoid b) => Monoid (a :# b) Source # | |
(NFData a, NFData b) => NFData (a :# b) Source # | |
Defined in Data.Type.Tuple | |
(Backprop a, Backprop b) => Backprop (a :# b) Source # | |
(Binary a, Binary b) => Binary (a :# b) Source # | Since: 0.1.5.1 |
(Regularize a, Regularize b) => Regularize (a :# b) Source # | |
(Initialize a, Initialize b) => Initialize (a :# b) Source # | |
Defined in Backprop.Learn.Initialize | |
Field1 (a :# b) (a' :# b) a a' Source # | |
Field2 (a :# b) (a :# b') b b' Source # | |
type Ref m (a :# b) Source # | |
Defined in Data.Type.Tuple | |
type Rep (a :# b) Source # | |
Defined in Data.Type.Tuple type Rep (a :# b) = D1 (MetaData ":#" "Data.Type.Tuple" "backprop-learn-0.1.0.0-LYs2l1OGpKTGmGWQXOoOXm" False) (C1 (MetaCons ":#" (InfixI RightAssociative 1) False) (S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness SourceStrict DecidedStrict) (Rec0 a) :*: S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness SourceStrict DecidedStrict) (Rec0 b))) |
pattern (:##) :: (Backprop a, Backprop b, Reifies s W) => BVar s a -> BVar s b -> BVar s (a :# b) Source #
Conversions
Consumption
uncurryT2 :: (a -> b -> c) -> (a :# b) -> c Source #
Uncurry a function to take in a T2
of its arguments
Since: 0.1.2.0
curryT2 :: ((a :# b) -> c) -> a -> b -> c Source #
Curry a function taking a T2
of its arguments
Since: 0.1.2.0
Lenses
t2_1 :: Lens (a :# b) (a' :# b) a a' Source #
Lens into the first field of a T2
. Also exported as _1
from
Lens.Micro.
t2_2 :: Lens (a :# b) (a :# b') b b' Source #
Lens into the second field of a T2
. Also exported as _2
from
Lens.Micro.
N-Tuples
Strict inductive N-tuple with a Num
, Fractional
, and Floating
instances.
It is basically "yet another HList", like the one found in Data.Type.Product and many other locations on the haskell ecosystem. Because it's inductively defined, it has O(n) random indexing, but is efficient for zipping and mapping and other sequential consumption patterns.
It is provided because of its Num
instance, making it useful for
backproup. Will be obsolete when Product
gets
numerical instances.
Since: 0.1.5.0
Instances
Conversions
Lenses
tTail :: Lens (T (a ': as)) (T (a ': bs)) (T as) (T bs) Source #
Lens into the tail of a T
Since: 0.1.5.0
Maybe
data PMaybe (a :: k -> Type) (b :: Maybe k) :: forall k. (k -> Type) -> Maybe k -> Type where #
A
contains nothing, and a PMaybe
f 'Nothing
contains an PMaybe
f ('Just a)f a
.
In practice this can be useful to write polymorphic functions/abstractions that contain an argument that can be "turned off" for different instances.
PNothing :: forall k (a :: k -> Type) (b :: Maybe k). PMaybe a (Nothing :: Maybe k) | |
PJust :: forall k (a :: k -> Type) (b :: Maybe k) (a1 :: k). a a1 -> PMaybe a (Just a1) |
Instances
PureProdC Maybe Backprop as => Backprop (TMaybe as) Source # | |
Decidable (TyPred (PMaybe (Sing :: k -> Type)) :: Predicate (Maybe k)) | Since: decidable-2.0.0 |
Provable (TyPred (PMaybe (Sing :: k -> Type)) :: Predicate (Maybe k)) | Since: decidable-2.0.0 |
SingI as => Auto (TyPred (PMaybe (Sing :: k -> Type)) :: Predicate (Maybe k)) (as :: Maybe k) | Since: decidable-2.0.0 |
ReifyConstraintProd Maybe Eq f as => Eq (PMaybe f as) | |
(ReifyConstraintProd Maybe Eq f as, ReifyConstraintProd Maybe Ord f as) => Ord (PMaybe f as) | |
Defined in Data.Type.Functor.Product | |
ReifyConstraintProd Maybe Show f as => Show (PMaybe f as) | |
(PureProdC Maybe Backprop as, PureProdC Maybe Regularize as) => Regularize (PMaybe TF as) Source # | |
pattern (:#?) :: (AllConstrainedProd Backprop a, AllConstrainedProd Backprop b, Reifies s W, PureProd Maybe a, PureProd Maybe b) => PMaybe (BVar s) a -> PMaybe (BVar s) b -> PMaybe (BVar s) (a :#? b) infixr 1 Source #
splitTupMaybe :: forall f a b. (PureProd Maybe a, PureProd Maybe b) => (forall a' b'. (a ~ Just a', b ~ Just b') => f (a' :# b') -> (f a', f b')) -> PMaybe f (a :#? b) -> (PMaybe f a, PMaybe f b) Source #