From this answer one learns how to implement the function \x y z -> f x (g y z)
in a pointless way in Haskell, where f
and g
are functions. And my question is
How to write the function
\x -> f (g x) (h x)
in a pointfree manner in Haskell? Heref
g
h
are functions for whichf (g x) (h x)
is defined.
The idea I currently have in mind is something like the following.
uncurry f (mapTuple ($ x) (g, h))
But several tries shows that this is fallacious; even the part map ($ x) [g, h]
is suspicious: what if g
and h
have different ranges?
In addition, readability is not too much an issue here.
Any help is sincerely appreciated.
As melpomene suggested, \x -> f (g x) (h x)
is equivalent to liftM2 f g h
.
When you have question concerning how to convert Haskell code into pointfree Haskell code, you can just try Pointfree.io.
It is a great tool which often can tell you when NOT to use pointfree code because it goes completely unreadable sometimes :-)