| Portability | GHC |
|---|---|
| Stability | experimental |
| Maintainer | conal@conal.net |
Data.Zip
Contents
Description
- type ZipTy f = forall a b. f a -> f b -> f (a, b)
- class Zip f where
- zipWith :: (Functor f, Zip f) => (a -> b -> c) -> f a -> f b -> f c
- zipWith3 :: (Functor f, Zip f) => (a -> b -> c -> d) -> f a -> f b -> f c -> f d
- apZip :: (Applicative h, Zip f) => ZipTy (h :. f)
- ppZip :: (Functor g, Zip g, Zip f) => ZipTy (g :. f)
- arZip :: (Arrow ~>, Unzip f, Zip g) => ZipTy (Arrw ~> f g)
- type UnzipTy f = forall a b. f (a, b) -> (f a, f b)
- class Unzip f where
- class Cozip f where
- cozip :: (Cozip f, Monoid_f f) => ZipTy f
- pairEdit :: (Functor m, Monoid (m ((c, d) -> (c, d)))) => (m c, m d) -> m ((c, d) -> (c, d))
- pairEditM :: MonadPlus m => (m c, m d) -> m ((c, d) -> (c, d))
Zippings
Type constructor class for zip-like things.
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 => Zip f where
zip = liftA2 (,)
instance (Applicative h, Zip f) => Zip (h :. f) where
zip = apZip
instance (Functor g, Zip g, Zip f) => Zip (g :. f)
where zip = ppZip
instance (Arrow (~>), Unzip f, Zip g) => Zip (Arrw (~>) f g) where
zip = arZip
instance (Monoid_f h, Cozip h) => Zip h where
zip = cozip
Also, if you have a type constructor that's a Functor and a Zip,
here is a way to define '(*)' for Applicative:
(<*>) = zipWith ($)
Minimum definitions for instances.
zipWith3 :: (Functor f, Zip f) => (a -> b -> c -> d) -> f a -> f b -> f c -> f dSource
Generalized zipWith
Unzipings
Unzippable. Minimal instance definition: either (a) unzip or (b)
both of fsts and snds. A standard template to substitute any
Functor f. But watch out for effects!
instance Functor f => Unzip f where {fsts = fmap fst; snds = fmap snd}
Methods
Arguments
| :: UnzipTy f | generalized unzip |
Arguments
| :: f (a, b) | |
| -> f a | First part of pair-like value |
Arguments
| :: f (a, b) | |
| -> f b | Second part of pair-like value |
Dual unzipings
Dual to Unzip.
Especially handy for contravariant functors (Cofunctor) . Use this
template (filling in f) :
instance Cofunctor f => Cozip f where
{ cofsts = cofmap fst ; cosnds = cofmap snd }
Methods
Arguments
| :: f a | |
| -> f (a, b) | Zip-like value from first part |
Arguments
| :: f b | |
| -> f (a, b) | Zip-like value from second part |
cozip :: (Cozip f, Monoid_f f) => ZipTy fSource
Ziping of Cozip values. Combines contribution of each.
Misc
pairEdit :: (Functor m, Monoid (m ((c, d) -> (c, d)))) => (m c, m d) -> m ((c, d) -> (c, d))Source
Turn a pair of sources into a source of pair-editors. See
http://conal.net/blog/posts/pairs-sums-and-reactivity/.
'Functor'\/'Monoid' version. See also pairEditM.
pairEditM :: MonadPlus m => (m c, m d) -> m ((c, d) -> (c, d))Source
Turn a pair of sources into a source of pair-editors. See
http://conal.net/blog/posts/pairs-sums-and-reactivity/.
Monad version. See also pairEdit.