Sometimes you want to fold a list of tuples into one tuple using different folding functions. For instance, in order to glue together a list of runState results, getting an (in some sense) combined state and a combined result.
Consider the following implementation:
wish :: (a -> a' -> a) -> (b -> b' -> b) -> (a,b) -> [(a', b')] -> (a,b)
wish lfn rfn x xs = foldl (\(a,b) -> (lfn a) *** (rfn b)) x xs
Although it works, I feel uncomfortable about this lambda. lfn *** rfn
by itself has a type of (a,b) -> (a -> a', b -> b')
, which I can't find a way to properly apply to a tuple without ever resorting to pattern matching. Is there a clear and elegant way I'm missing? It could be a library function of type (a,a') -> (a -> a, a' -> a') -> (a, a')
or a whole different approach, maybe.