Copyright | (c) Justin Le 2018 |
---|---|
License | BSD3 |
Maintainer | justin@jle.im |
Stability | experimental |
Portability | non-portable |
Safe Haskell | None |
Language | Haskell2010 |
Canonical strict tuples with Num
instances for usage with backprop.
This is here to solve the problem of orphan instances in libraries and
potential mismatched tuple types.
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.
Since: 0.1.1.0
- data T2 a b = T2 !a !b
- t2Tup :: T2 a b -> (a, b)
- tupT2 :: (a, b) -> T2 a b
- t2_1 :: Lens (T2 a b) (T2 a' b) a a'
- t2_2 :: Lens (T2 a b) (T2 a b') b b'
- data T3 a b c = T3 !a !b !c
- t3Tup :: T3 a b c -> (a, b, c)
- tupT3 :: (a, b, c) -> T3 a b c
- t3_1 :: Lens (T3 a b c) (T3 a' b c) a a'
- t3_2 :: Lens (T3 a b c) (T3 a b' c) b b'
- t3_3 :: Lens (T3 a b c) (T3 a b c') c c'
Two-tuples
Strict 2-tuple with a Num
instance.
Since: 0.1.1.0
T2 !a !b |
Bifunctor T2 Source # | |
Functor (T2 a) Source # | |
(Eq b, Eq a) => Eq (T2 a b) Source # | |
(Floating a, Floating b) => Floating (T2 a b) Source # | |
(Fractional a, Fractional b) => Fractional (T2 a b) Source # | |
(Data b, Data a) => Data (T2 a b) Source # | |
(Num a, Num b) => Num (T2 a b) Source # | |
(Ord b, Ord a) => Ord (T2 a b) Source # | |
(Read b, Read a) => Read (T2 a b) Source # | |
(Show b, Show a) => Show (T2 a b) Source # | |
Generic (T2 a b) Source # | |
(Semigroup a, Semigroup b) => Semigroup (T2 a b) Source # | |
(Monoid a, Monoid b) => Monoid (T2 a b) Source # | |
(NFData a, NFData b) => NFData (T2 a b) Source # | |
Field1 (T2 a b) (T2 a' b) a a' Source # | |
Field2 (T2 a b) (T2 a b') b b' Source # | |
type Rep (T2 a b) Source # | |
Conversions
If using lens, the two conversion functions can be chained with prisms and traversals and other optics using:
iso
tupT2
t2Tup
::Iso'
(a, b) (T2
a b)
t2Tup :: T2 a b -> (a, b) Source #
Convert to a Haskell tuple.
Forms an isomorphism with tupT2
.
@since 0.1.1.0
Lenses
t2_1 :: Lens (T2 a b) (T2 a' b) a a' Source #
Lens into the first field of a T2
. Also exported as _1
from
Lens.Micro.
t2_2 :: Lens (T2 a b) (T2 a b') b b' Source #
Lens into the second field of a T2
. Also exported as _2
from
Lens.Micro.
Three-tuples
Strict 3-tuple with a Num
instance.
Since: 0.1.1.0
T3 !a !b !c |
Bifunctor (T3 a) Source # | |
Functor (T3 a b) Source # | |
(Eq c, Eq b, Eq a) => Eq (T3 a b c) Source # | |
(Floating a, Floating b, Floating c) => Floating (T3 a b c) Source # | |
(Fractional a, Fractional b, Fractional c) => Fractional (T3 a b c) Source # | |
(Data c, Data b, Data a) => Data (T3 a b c) Source # | |
(Num a, Num b, Num c) => Num (T3 a b c) Source # | |
(Ord c, Ord b, Ord a) => Ord (T3 a b c) Source # | |
(Read c, Read b, Read a) => Read (T3 a b c) Source # | |
(Show c, Show b, Show a) => Show (T3 a b c) Source # | |
Generic (T3 a b c) Source # | |
(Semigroup a, Semigroup b, Semigroup c) => Semigroup (T3 a b c) Source # | |
(Monoid a, Monoid b, Monoid c) => Monoid (T3 a b c) Source # | |
(NFData a, NFData b, NFData c) => NFData (T3 a b c) Source # | |
Field1 (T3 a b c) (T3 a' b c) a a' Source # | |
Field2 (T3 a b c) (T3 a b' c) b b' Source # | |
Field3 (T3 a b c) (T3 a b c') c c' Source # | |
type Rep (T3 a b c) Source # | |
Conversions
If using lens, the two conversion functions can be chained with prisms and traversals and other optics using:
iso
tupT3
t2Tup
::Iso'
(a, b, c) (T3
a b c)
Lenses
t3_1 :: Lens (T3 a b c) (T3 a' b c) a a' Source #
Lens into the first field of a T3
. Also exported as _1
from
Lens.Micro.