Unix-like pipes in Haskell
From the euclid post, I wanted to test that no two composites a unit distance
apart share any prime factors. It seemed like I was doing half in BASH and half
in Haskell, when I realized something interesting: flip the arguments of
Haskell's $-operator, and you've got something very similar to UNIX pipes :).
Of course, a quick Google search proved I was not the first to think of this, but it's still a neat trick. And since I am learning Haskell, I put this in for my own notes:
Besides being in a more readable "cook-book" -- this is how you do it step for
step -- style, stddev1 also allows me to comment out any trailing part of the
line without altering the first steps. Since $ is just syntax-sugarSyntactic sugarNotation that is easier to read or write but adds no new capability to the language. for
avoiding parens, stddev2 should be more familiar to many C++/Java programmers
(i.e. sqrt((1/n) * sum(more nested stuff))). The difference is only notational
of course, somewhat similar to that of polish vs reverse-polish notationReverse Polish notationPostfix notation where the operator follows its operands, so no parentheses are needed.en.wikipedia.org.