Portability | non-portable |
---|---|
Stability | experimental |
Maintainer | generics@haskell.org |
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.
The important concepts for zipWithM
are structural equivalence and
corresponding elements. For zipWithM
to be successful (and not fail
),
its two container arguments must have exactly the same 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, zipWithM
will fail
.
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.
Documentation
newtype ZipWith m a b c Source
The type of a generic function that takes two arguments of two different types and returns a value of a third type in a Monad.
ZipWith | |
|
:: (Monad m, FRep3 (ZipWith m) f) | |
=> (a -> b -> m c) | Binary operator on elements of containers. |
-> f a | Container of |
-> f b | Container of |
-> m (f c) | Container of |
Combine two structurally equivalent containers into one by applying a
function to every corresponding pair of elements. Fails if (1) the binary
operator fails or (2) f a
and f b
have different shapes.