emgm-0.3.1: Extensible and Modular Generics for the MassesSource codeContentsIndex

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.

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))
newtype ZipWith a b c Source
The type of a generic function that takes two arguments of two different types and optionally returns a value of a third type.
selZipWith :: a -> b -> Maybe c
show/hide Instances
:: 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.
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