emgm-0.1: Extensible and Modular Generics for the MassesSource codeContentsIndex
Generics.EMGM.Functions.ZipWith
Portabilitynon-portable
Stabilityexperimental
Maintainergenerics@haskell.org
Description

Summary: Generic function that applies a (non-generic) function to every pair of corresponding elements in two structurally equivalent polymorphic values to produce a third (also structurally equivalent) value with the result of each application in every element location.

zipWith is a generic version of the Prelude zipWith function. It works on all supported container datatypes of kind * -> *.

The important concepts for zipWith are structural equivalence and corresponding elements. A regular, algebraic datatype can be visualized as some sort of tree representing its structure. For zipWith to be successful (and not return Nothing), its two container arguments must have exactly the same tree shape. If the shapes of the arguments differ, then it is unclear what the shape of the result is supposed to be. As a result, zipWith safely returns Nothing.

Corresponding elements are those elements that are located in the same place in the tree of each argument. If you were to traverse the tree to get to element x in one tree, then its corresponding element y in the other tree should require the exact same path to reach it.

See also Generics.EMGM.Functions.UnzipWith.

Synopsis
newtype ZipWith a b c = ZipWith {
selZipWith :: a -> b -> Maybe c
}
zipWith :: FRep3 ZipWith f => (a -> b -> c) -> f a -> f b -> Maybe (f c)
zip :: FRep3 ZipWith f => f a -> f b -> Maybe (f (a, b))
Documentation
newtype ZipWith a b c Source
Type for zipWith
Constructors
ZipWith
selZipWith :: a -> b -> Maybe c
show/hide Instances
zipWithSource
:: FRep3 ZipWith f
=> a -> b -> cBinary operator on elements of containers.
-> f aContainer of a-values.
-> f bContainer of b-values.
-> Maybe (f c)Container of c-values if successful or Nothing if failed.
Combine two structurally equivalent containers into one by applying a function to every corresponding pair of elements. Returns Nothing if f a and f b have different shapes. All other functions in this module are derived from zipWith.
zip :: FRep3 ZipWith f => f a -> f b -> Maybe (f (a, b))Source
Combine two containers into a single container with pairs of the original elements. See zipWith for restrictions. This is a generic version of the Prelude function of the same name.
Produced by Haddock version 2.4.2