[Haskell-cafe] Function application like a Unix pipe

Scherrer, Chad Chad.Scherrer at pnl.gov
Fri Nov 18 12:44:57 EST 2005


I'm still trying to settle on a "feel" for good programming style in
Haskell. One thing I've been making some use of lately is

(\|) = flip ($)
infixl 0 \|

Then expressions like

f4 $ f3 $ f2 $ f1 $ x

become

x  \|
f1 \|
f2 \|
f3 \|
f4

I've seen something like this on haWiki using (#), but I prefer this
notation because it looks like a Unix pipe, which is exactly how it's
used. 

This style makes the sequential feel of monadic do notation available to
non-monadic functions, and would seem to ease the initial confusion most
people experience when they first program using lazy evaluation. Many
newbies have experience with Unix pipes, and this notation makes that
analogy explicit.

I have a couple of questions about this...

First, it would be convenient if ($) could appear in an fi without extra
parentheses, but this would require "infixl (-1) \|". Is there a reason
this isn't allowed? The current fixities don't seem to allow much room
for expansion. Would it be possible to either (1) allow negative and/or
fractional fixities, or (2) shift and spread out the current fixities to
allow more flexibility in the introduction of new operators?

I'm also trying to determine to what extent this style should really be
used. Does anyone see this as "bad style"? Is there an argument why this
might not be such a good way to ease someone into the language? 

Chad Scherrer
Computational Mathematics Group
Pacific Northwest National Laboratory

"Time flies like an arrow; fruit flies like a banana." -- Groucho Marx


More information about the Haskell-Cafe mailing list