I have no idea how useful the application would be, but I got curious about it because of this C++ answer to a question of mine.
So, given, say, a ternary f
and a binary g
, e.g.
f x y z = x + 10*y + 100*z
g x y = x + 10*y
how can I get a function h
such that the following holds?
h f g 1 2 3 4 5 == (321, 54)
Clearly I can define
h f g = \x y z v w -> (f x y z, g v w)
But I was curious to know if it could be done in point-free style for every arities m
and n
, using some existing abstraction.
For this specific example (m == 3 && n == 2
) pointfree.io shows that the result becomes unreadable:
h = flip . ((flip . ((flip . (((.) . (.) . (,)) .)) .)) .)
but I'm still curious if something else exists.
For fun, I've tried to apply combinatory logic mecanically to derive a formula, but still only for the specific case of m == 3 && n == 2
:
b = (.) -- bluebird (names from "To Mock a Mockingbird")
c = flip -- cardinal (names from "To Mock a Mockingbird")
p = (,)
f x y z = x + 10*y + 100*z
g x y = x + 10*y
{-
p(fxyz)(gvw) = ?xyzvw, with ? in terms of p, f, g and known birds
(p(fxyz))(gvw)
B(B(p(fxyz)))gvw
CBg(B(p(fxyz)))vw
B(CBg)B(p(fxyz))vw
B(B(CBg)B)p(fxyz)vw
B(B(B(CBg)B)p)(fxy)zvw
B(B(B(B(CBg)B)p))(fx)yzvw
B(B(B(B(B(CBg)B)p)))fxyzvw
B(B(B(B(B(CBB)(CB)g)p)))fxyzvw
B(B(B(BB(B(CBB)(CB))gp)))fxyzvw
B(B(BB(BB(B(CBB)(CB))g)p))fxyzvw
B(B(B(BB)(BB(B(CBB)(CB)))gp))fxyzvw
B(BB(B(BB)(BB(B(CBB)(CB)))g)p)fxyzvw
BB(BB(B(BB)(BB(B(CBB)(CB)))g))pfxyzvw
B(BB)(B(BB)(B(BB)(BB(B(CBB)(CB)))))gpfxyzvw
C(C(B(BB)(B(BB)(B(BB)(BB(B(CBB)(CB))))))p)fgxyzvw
-}
h = c (c (b (b b) (b (b b) (b (b b) (b b (b (c b b) (c b)))))) p)
h f g 1 2 3 4 5 == (321, 54) -- True