inf-backprop-0.2.0.0: Automatic differentiation and backpropagation.
Copyright(C) 2025 Alexey Tochin
LicenseBSD3 (see the file LICENSE)
MaintainerAlexey Tochin <Alexey.Tochin@gmail.com>
Safe HaskellSafe-Inferred
LanguageHaskell2010

Numeric.InfBackprop.Utils.Tuple

Description

Utility functions for working with tuples.

Synopsis
  • cross :: (a -> b) -> (c -> d) -> (a, c) -> (b, d)
  • cross3 :: (a0 -> b0) -> (a1 -> b1) -> (a2 -> b2) -> (a0, a1, a2) -> (b0, b1, b2)
  • fork :: (t -> a) -> (t -> b) -> t -> (a, b)
  • fork3 :: (t -> a0) -> (t -> a1) -> (t -> a2) -> t -> (a0, a1, a2)
  • curry3 :: ((a, b, c) -> d) -> a -> b -> c -> d
  • uncurry3 :: (a -> b -> c -> d) -> (a, b, c) -> d
  • biCross :: (a -> b -> c) -> (d -> e -> f) -> (a, d) -> (b, e) -> (c, f)
  • biCross3 :: (a -> b -> c) -> (d -> e -> f) -> (g -> h -> l) -> (a, d, g) -> (b, e, h) -> (c, f, l)

Documentation

cross :: (a -> b) -> (c -> d) -> (a, c) -> (b, d) Source #

Applies two functions to the components of a tuple.

cross3 :: (a0 -> b0) -> (a1 -> b1) -> (a2 -> b2) -> (a0, a1, a2) -> (b0, b1, b2) Source #

Applies three functions to the components of a triple.

Examples

Expand
>>> import GHC.Num ((+), (-), (*))
>>> cross3 (+1) (*2) (\x -> x - 3) (3, 4, 10)
(4,8,7)

fork :: (t -> a) -> (t -> b) -> t -> (a, b) Source #

Applies two functions to the same argument and returns a tuple of results.

Examples

Expand
>>> import GHC.Num ((+), (*))
>>> fork (+1) (*2) 3
(4,6)

fork3 :: (t -> a0) -> (t -> a1) -> (t -> a2) -> t -> (a0, a1, a2) Source #

Applies three functions to the same argument and returns a triple of results.

>>> import GHC.Num ((+), (-), (*))

Examples

Expand
>>> fork3 (+1) (*2) (\x -> x - 3) 5
(6,10,2)

curry3 :: ((a, b, c) -> d) -> a -> b -> c -> d Source #

Curries a function on triples.

Examples

Expand
>>> import GHC.Num ((+))
>>> f (x, y, z) = x + y + z
>>> g = curry3 f
>>> g 1 2 3
6

uncurry3 :: (a -> b -> c -> d) -> (a, b, c) -> d Source #

Uncurries a function on triples.

Examples

Expand
>>> import GHC.Num ((+))
>>> f x y z = x + y + z
>>> g = uncurry3 f
>>> g (1, 2, 3)
6

biCross :: (a -> b -> c) -> (d -> e -> f) -> (a, d) -> (b, e) -> (c, f) Source #

Applies two binary functions to the components of two tuples.

Examples

Expand
>>> import GHC.Num ((+), (*))
>>> biCross (+) (*) (1, 2) (3, 4)
(4,8)

biCross3 :: (a -> b -> c) -> (d -> e -> f) -> (g -> h -> l) -> (a, d, g) -> (b, e, h) -> (c, f, l) Source #

Applies three binary functions to the components of two triples.

Examples

Expand
>>> import GHC.Num ((+), (*), (-))
>>> biCross3 (+) (*) (-) (1, 2, 10) (3, 4, 5)
(4,8,5)