Good style on "." and "$" pipeline?

I am very new to Haskell, but what I've discovered so far is that the
application operator $ is used to improve code readability. It can
sometimes be used eliminate the need for parentheses that break
natural left-to-right reading.
Hoogle covers an example:
http://hackage.haskell.org/packages/archive/base/latest/doc/html/Prelude.htm...
Cheers!
On Tue, Aug 21, 2012 at 1:34 PM, Carlos J. G. Duarte
Hi. Often I see the following pattern to build function "pipelines":
x = f1 . f2 $ fn arg
They use the "$" just before the last function call. I never got much into it: when to use the "." or the "$"? I think today I figured it out: => "." is a function composition operator: used to "merge" functions; => "$" is a function application operator: used to apply a function to its arguments.
If this reasoning is correct, I think the following should be a more adequate pattern:
x = f1 . f2 . fn $ arg
To merge/compose all functions first and apply the composed function to its parameter(s). Am I correct on this? Thx
_______________________________________________ Beginners mailing list Beginners@haskell.org http://www.haskell.org/mailman/listinfo/beginners

On Tue, Aug 21, 2012 at 09:34:49PM +0100, Carlos J. G. Duarte wrote:
Hi. Often I see the following pattern to build function "pipelines":
x = f1 . f2 $ fn arg
They use the "$" just before the last function call. I never got much into it: when to use the "." or the "$"? I think today I figured it out: => "." is a function composition operator: used to "merge" functions; => "$" is a function application operator: used to apply a function to its arguments.
If this reasoning is correct, I think the following should be a more adequate pattern:
x = f1 . f2 . fn $ arg
To merge/compose all functions first and apply the composed function to its parameter(s). Am I correct on this? Thx
Yes, you are absolutely correct. But sometimes people do something like f1 . f2 $ fn arg if for some reason they are thinking of "fn arg" as a "primitive" starting point, and then applying a pipeline of functions f2, f1 to that. But it is really just a different point of view. In any case, both (f1 . f2 . fn $ arg) and (f1 . f2 $ fn arg) are perfectly good style. Having more than one $, like (f1 $ f2 $ fn $ arg), is frowned upon. -Brent

On Tue, Aug 21, 2012 at 10:34 PM, koomi
On 21.08.2012 22:43, Brent Yorgey wrote:
Having more than one $, like (f1 $ f2 $ fn $ arg), is frowned upon. Care to explain why this is considered bad? I don't see anything wrong with this.
It's just a matter of taste. Personally, I usually prefer using many ($)s rather than combining (.)s and ($)s on the same "phrase". For example, I prefer foo = finish $ doSomethingOther $ doSomething $ initialArg to foo = finish . doSomethingOther . doSomething $ initialArg It gives me a feel of simmetry. You may even align the $s, either on the left or on the right. But, like I said, it's just a matter of taste =). Cheers, -- Felipe.

On Wed, Aug 22, 2012 at 3:41 AM, Felipe Almeida Lessa
On Tue, Aug 21, 2012 at 10:34 PM, koomi
wrote: On 21.08.2012 22:43, Brent Yorgey wrote:
Having more than one $, like (f1 $ f2 $ fn $ arg), is frowned upon. Care to explain why this is considered bad? I don't see anything wrong with this.
It's just a matter of taste. Personally, I usually prefer using many ($)s rather than combining (.)s and ($)s on the same "phrase".
It is a bit more than a matter of taste : the (.)s then one ($) style allows easier and clearer refactoring because each part of the function pipeline can be just copy pasted somewhere else, for instance you can get from :
bigFunc = f1 . f2 . f3 . f4 $ arg
to
bigFunc = f1 . meaningfulFunc . f4 $ arg
meaningfulFunc = f2 . f3
without rewriting a bit of your pipeline to change $ to . or add a point to meaningfulFunc (note that I ignore the monomorphism restriction here, I would give those function signatures anyway since they're top-level). I find this style makes it easier to reason about in a purely "pipelinesque" way (focused on functions and their combinations). -- Jedaï

On Tue, Aug 21, 2012 at 9:34 PM, koomi
On 21.08.2012 22:43, Brent Yorgey wrote:
Having more than one $, like (f1 $ f2 $ fn $ arg), is frowned upon. Care to explain why this is considered bad? I don't see anything wrong with this.
Experientially, we see it a lot in #xmonad from beginners combining stuff together with a certain amont of cargo-culting (being beginners and usually quite unfamiliar with Haskell). I've been moving toward using ($) to separate logical "phrases" and (.) within the phrases, to make it easier to see which things go with which. Since layoutHook is rather agglutinative, this helps a lot. -- brandon s allbery allbery.b@gmail.com wandering unix systems administrator (available) (412) 475-9364 vm/sms

"agglutinative" That is one crazy word.
On Wed, Aug 22, 2012 at 10:09 AM, Brandon Allbery
On Tue, Aug 21, 2012 at 9:34 PM, koomi
wrote: On 21.08.2012 22:43, Brent Yorgey wrote:
Having more than one $, like (f1 $ f2 $ fn $ arg), is frowned upon. Care to explain why this is considered bad? I don't see anything wrong with this.
Experientially, we see it a lot in #xmonad from beginners combining stuff together with a certain amont of cargo-culting (being beginners and usually quite unfamiliar with Haskell).
I've been moving toward using ($) to separate logical "phrases" and (.) within the phrases, to make it easier to see which things go with which. Since layoutHook is rather agglutinative, this helps a lot.
-- brandon s allbery allbery.b@gmail.com wandering unix systems administrator (available) (412) 475-9364 vm/sms
_______________________________________________ Beginners mailing list Beginners@haskell.org http://www.haskell.org/mailman/listinfo/beginners
-- Cell: 1.630.740.8204

David Johnson
"agglutinative" That is one crazy word.
It's commonly used in linguistics, but in a somewhat more specialized sense. See http://en.wikipedia.org/wiki/Agglutinative_language . -Keshav
participants (10)
-
Brandon Allbery
-
Brent Yorgey
-
Carlos J. G. Duarte
-
Chaddaï Fouché
-
Darren Grant
-
David Johnson
-
Felipe Almeida Lessa
-
Keshav Kini
-
koomi
-
Ozgur Akgun