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.
|