Re: [Haskell-cafe] Function application like a Unix pipe

"Albert Lai"
I offer a simpler, more direct, and pre-existing correspondence between a functional programming construct and unix pipes:
Maybe my point wasn't clear. Of course this idea of comparing lazy evaluation to Unix pipes is very old (long before July 2004, I'm sure). The point I'm making is that there is an old idea that may be underused. We use ($) all over the place, but if there are a lot of them (and especially if they are spread over several lines) it becomes awkward to read the whole thing backward to trace through the function from beginning to end. In these cases, it's much simpler to use (\|) = flip ($) -- (#) seems to me too pretty for other purposes to use it here. infixl 0 \| -- Again, why can't this be negative or Fractional?? What I'm asking is really a question of pedagogy and style. This style seems reasonable to me. OTOH, there are some reasons not to do things in this way. Maybe any function big enough to benefit from writing it this way should be broken up anyway. Or maybe getting used to this style where the laziness is right in your face could make it more difficult for people to learn to reason through less obvious laziness. I'm really trying to figure out whether this approach is worth pursuing, rather than imply that this is a completely original idea. Chad Scherrer Computational Mathematics Group Pacific Northwest National Laboratory "Time flies like an arrow; fruit flies like a banana." -- Groucho Marx

On Tue, Nov 22, 2005 at 02:09:40PM -0800, Scherrer, Chad wrote:
(\|) = flip ($) -- (#) seems to me too pretty for other purposes to use it here. infixl 0 \| -- Again, why can't this be negative or Fractional??
I have a ? operator that does the same thing. Next time I use it I'll check if \| looks better. Best regards Tomasz

Scherrer, Chad wrote:
Maybe my point wasn't clear. Of course this idea of comparing lazy evaluation to Unix pipes is very old (long before July 2004, I'm sure). The point I'm making is that there is an old idea that may be underused.
It is, and only because (.) is defined all wrong! The unix pipe is actually function composition. Its argument (standard input) isn't explicitly mentioned, so the analogous Haskell code should do the same. However, function composition reads backwards, which makes code quite unreadable, especially when (.), (>>=) and `liftM` (which also has an all wrong fixity) are mixed. Im summary, I'd define infixl 0 # infixl 1 >># infixl 2 \| (#) = flip ($) (>>#) = flip liftM (\|) = flip (.) -- though I'm using (&) The unix pipe becomes (filter ("foo" `isPrefixOf`) \| sort \| nub) or something, which is rather neat, and (#) is used to call "member functions", as in some_map # add key value # add something or_other # delete old_trash which actually gives the result one expects when reading it top to bottom. In summary, (.) is tremendously useful, but it would be even better if it had the correct argument order. Unfortunately, this cannot be corrected any more. Udo. -- "God is real, unless declared as an Integer." - Unknown Source

On Wed, Nov 23, 2005 at 11:17:25AM +0100, Udo Stenzel wrote:
infixl 2 \| (\|) = flip (.) -- though I'm using (&)
The unix pipe becomes (filter ("foo" `isPrefixOf`) \| sort \| nub) or something, which is rather neat, and (#) is used to call "member functions", as in
Why not use Control.Arrow.>>> ? The instance for (->) is exactly what you want, and the syntax is quite nice: (filter ("foo" `isPrefixOf`) >>> sort >>> nub) BTW, using sort before nub is a bit pointless. In fact, using nub for longer lists is a bad idea. Best regards Tomasz

On Wed, 23 Nov 2005, Udo Stenzel wrote:
Scherrer, Chad wrote:
Maybe my point wasn't clear. Of course this idea of comparing lazy evaluation to Unix pipes is very old (long before July 2004, I'm sure). The point I'm making is that there is an old idea that may be underused.
It is, and only because (.) is defined all wrong!
Since (a . b) x a $ b x a (b x) are equivalent, do you also want to reverse function and argument in order to match argument order of . and $ ? That is x (b . a) x b $ a (x b) a ?
participants (4)
-
Henning Thielemann
-
Scherrer, Chad
-
Tomasz Zielonka
-
Udo Stenzel