Sometimes I have two functions of the form:
f :: a -> (b1,b2)
h :: b1 -> b2 -> c
and I need the composition g. I solve this by changing h to h’:
h' :: (b1,b2) -> c
Can you please show me (if possible) a function m, so that:
(h . m . f) == (h' . f)
Or another way to deal with such situations. Thanks.
What you’re looking to do is to take a function that operates on curried arguments,
h, and apply it to the result off, which is a tuple. This process, turning a function of two arguments into a function that takes one argument that is a tuple, is called uncurrying. We have, from Data.Tuple:So now we can write:
Another tricky way to think of this is via an applicative functor,
Idea from Conor McBride, who’d write it as:
(|f fst snd|) . fI think.