|
Data.Pair | Portability | GHC | Stability | experimental | Maintainer | conal@conal.net |
|
|
|
|
|
Description |
Pair-related type constructor classes. See Data.Fun for similar classes.
|
|
Synopsis |
|
|
|
|
Pairings
|
|
type PairTy f = forall a b. f a -> f b -> f (a, b) | Source |
|
Type of pair method
|
|
|
Type constructor class for pair-like things. Generalizes zip.
Here are some standard instance templates you can fill in. They're not
defined in the general forms below, because they would lead to a lot of
overlap.
instance Applicative f => Pair f where
pair = liftA2 (,)
instance (Applicative h, Pair f) => Pair (h :. f) where
pair = apPair
instance (Functor g, Pair g, Pair f) => Pair (g :. f)
where pair = ppPair
instance (Arrow (~>), Unpair f, Pair g) => Pair (Arrw (~>) f g) where
pair = arPair
instance (Monoid_f h, Copair h) => Pair h where
pair = copair
| | Methods | | :: PairTy f | Form a pair-like value (generalizes zip)
|
|
| | Instances | |
|
|
|
Handy for Pair instances
|
|
|
Handy for Pair instances
|
|
|
Pairing of Arrw values. Warning: definition uses arr, so only
use if your arrow has a working arr.
|
|
Unpairings
|
|
type UnpairTy f = forall a b. f (a, b) -> (f a, f b) | Source |
|
Type of unpair method. Generalizes unzip.
|
|
|
Dissectable as pairs. Minimal instance definition: either (a)
unpair or (b) both of pfst and psnd.
A standard template to substitute any Functor f. But watch out for
effects!
instance Functor f => Unpair f where {pfst = fmap fst; psnd = fmap snd}
| | Methods | | :: UnpairTy f | Deconstruct pair-like value
|
| | | :: | | => f (a, b) | | -> f a | First part of pair-like value
|
| | | :: | | => f (a, b) | | -> f b | Second part of pair-like value
|
|
| | Instances | |
|
|
Dual unpairings
|
|
|
Dual to Unpair.
Especially handy for contravariant functors (Cofunctor) . Use this
template (filling in f) :
instance Cofunctor f => Copair f where
{ cofst = cofmap fst ; cosnd = cofmap snd }
| | Methods | | :: | | => f a | | -> f (a, b) | Pair-like value from first part
|
| | | :: | | => f b | | -> f (a, b) | Pair-like value from second part
|
|
| | Instances | |
|
|
|
Pairing of Copair values. Combines contribution of each.
|
|
Produced by Haddock version 2.3.0 |