chaining multi-parameter functions
function, haskell
Solution
Searching Hoogle for functions with the right signature reveals `on` from Data.Function. According to its documentation,
g `on` f
seems to be what you want.
Problem
Suppose I have two functions, `f:X->Y` and `g:Y*Y->Z`. I want to make a third function, `h(a, b) = g(f(a), f(b))`. ``` h a b = g (f a) (f b) ``` Is there any way to write it like `h(a, b) = g*f (a, b)`? And what if `h(a,b,c,d) = g2*g1*f2*f1 (a,b,c,d)`, where `g_i` takes 2 args?