Proposal: Add (&) to Data.Function

Dan Burton at
Tue Nov 20 21:32:42 CET 2012

> Functional metapost called it (#). But for me (>>>) is ok. It is even more
> descriptive than (&).

The reason I feel that >>> is inadequate is because it requires that you
use either parens or $ in order to finally apply the chain of functions to
a value. Also, being part of a typeclass can scare newcomers from
using/understanding it.

(foo >>> bar >>> baz) val
foo >>> bar >>> baz $ val


Part of the reason I like |> is because it *is* a little more clutter-y
than &. This forces you to use it prudently, with adequate whitespace. For
example, when I was writing a StackOverflow answer[1] a few days ago, I
found that using this operator was unreadable unless I used additional
newlines. Lining up the |> operators actually produces a rather nice visual
effect, as if you were entering each transformation at a command prompt.
The vertical bars lining up is also nice. Consider the "butt-ugly" code
(according to Thomas):

 ("hello","world")  &  _1.traverse %~ toUpper  & _2 .~ 42

Rewritten with whitespace, it can look much prettier:

("Hello", "world")
  |> _1.traverse %~ toUpper
  |> _2          .~ 42

This style is reminiscent of the style often used for long chains of
object-oriented method calls.

& works just as well with the additional whitespace, but complaints about
the line noise caused by |> go away also.


-- Dan Burton
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the Libraries mailing list