While learning Haskell, I came across a challenge to find two functions f
and g
, such that f g
and f . g
are equivalent (and total, so things like f = undefined
or f = (.) f
don't count). The given solution is that f
and g
are both equal to \x -> x . x
(or join (.)
).
(I note that this isn't Haskell-specific; it can be expressed in pure combinatory logic as "find f
and g
such that f g = B f g
", and the given solution would then translate to f = g = W B
.)
I understand why the given solution works when I expand it out, but I don't understand how you'd ever find it if you didn't already know it. Here's how far I can get:
f g = f . g
(given)f g z = (f . g) z
(eta-expansion of both sides)f g z = f (g z)
(simplify the RHS)
And I don't know how to proceed from there. What would I do next in trying to find a solution?
f
beid
andg
be any function.id g = g = id . g
. – Bohunk