I sometimes see h $ g $ f x y z and other times see h . g $ f x y z. I understand that the former is equivalent to h (g (f x y z)) and the latter equivalent to (\p -> h(g p))(f x y z).
Is it possible to reason that one is to be preferred over the other? If so, what is that reasoning?
↑ best one for me. The . points my attention at “this is pointfree, consider it as one”, is clearer than the dollar. I usually see/use $ as “save you matching some parentheses”.
The reason people prefer chains of composition is, e.g., to use your example, h $ g is not a type-correct and meaningful unit on its own, while h . g is. So the latter encourages building compositional units which are easier to refactor, substitute, and shuffle around.
I guess is about personal preference. I do prefer h . g $ f x y z because
It is slightly easier to refactor
some_thing = h . g $ f x y z
some_thing = expressive_name $ f x y z
where expressive_name = h . g -- This is just copy-paste
some_thing' = h $ g $ f x y z
some_thing' = expressive_name $ f x y z
where expressive_name = h . g -- You have to change the $ by . or
expressive_name x = h $ g x -- You have to add the extra x
and easier to read
some = h . g $ f x y z -- you can focus on the two importan parts function - argument
-- | |- applied to
-- |- some func
some = h $ g $ f x y z -- less clear what it means in my opinion
-- | |- applied to
-- |- applied to
Clearly a too long post for something not important…