Coding Problems!! Please help

John Hughes
Wed, 17 Apr 2002 11:16:42 +0200 (MET DST)

	I am currently working on an assignment with requires us to write in
    Haskell. I am having trouble with "pipeline". The required textbook
    called, "The Craft of Functional Programming" 2nd Edition.  There is a
    pipeline example, which I find it useful in my assignment, but for some
    reason, there may be a typo in the pipeline syntax, which is ">.>". Coz it
    doesn't compile.

Your problem is that that book defines and uses a non-standard composition

The standard Haskell function composition is written just ".", defined by

    (f . g) x = f (g x)

Notice that in f . g, it is *g* which is applied first to the argument, and f
which is applied to the result of that. That is, composition is "backwards" in
some sense. Here's an example:

     sqrt . abs

takes the absolute value of its argument first, and then the square root of
that, not the absolute value of the square root (which would fail for negative

Many people (including mathematicians) prefer to write the arguments of
compose in the other order, so that the first function to be applied is the
first one you write. To make that possible, Simon Thompson defines

    (f >.> g) x = g (f x)

So now you would write the example above as

    abs >.> sqrt

You take the absolute value first, so you write it first.

Regardless of which you prefer, the important thing to understand is that >.>
IS NOT PART OF THE HASKELL STANDARD. So if you want to use it, you have to
include the definition above in your own program.

John Hughes