emgm-0.4: Extensible and Modular Generics for the Masses




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.



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.




selZipWith :: a -> b -> m c




:: (Monad m, FRep3 (ZipWith m) f) 
=> (a -> b -> m c)

Binary operator on elements of containers.

-> f a

Container of a-values.

-> f b

Container of b-values.

-> m (f c)

Container of c-values within a Monad m.

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.

zipWith :: FRep3 (ZipWith Maybe) f => (a -> b -> c) -> f a -> f b -> Maybe (f c)Source

A specialized version of zipWithM for the Maybe monad and a binary operator that does not fail. Generic version of Prelude.zipWith.

zip :: FRep3 (ZipWith Maybe) f => f a -> f b -> Maybe (f (a, b))Source

A specialized version of zipWith for pairs. Generic version of Prelude.zip.