[Haskell-cafe] Function application like a Unix pipe

Udo Stenzel u.stenzel at web.de
Wed Nov 23 05:17:25 EST 2005

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.

"God is real, unless declared as an Integer." - Unknown Source
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
Url : http://www.haskell.org//pipermail/haskell-cafe/attachments/20051123/9f944d67/attachment.bin

More information about the Haskell-Cafe mailing list