Fri Dec 29 12:01:37 EST 2006

```Steve Schafer wrote:
>
> Here's the essence of the problem. If I have this:
>
>  process1 x y =
>    let u = foo x y;
>        v = bar u;
>        w = baz v
>    in  w
>
> I can easily rewrite it in point-free style:
>
>  process1 = baz . bar . foo

Not unless you have a much fancier version of function composition,
like...

>
> But if I have this:
>
>  process2 x y =
>    let u = foo x y;
>        v = bar u;
>        w = baz v u
>    in  w
>
> then I can't avoid naming and using an intermediate variable. And that
> annoys me. The u in process2 is of no more value to me (pardon the
> pun) as the one in process1, but I am forced to use it simply because
> the data flow is no longer strictly linear.
>
> The reason I brought up monads as a possible means of managing this
> certain specific "shapes" of nonlinear data flow, which suggested to
> me that maybe there was a monadic approach to managing nonlinear data
> flow in a more general way. Of course, if there is a non-monadic,
> purely functional way to do it, that would be even better, but I've
> never seen such a thing (short of doing lots of tupling and
> un-tupling).

-- Use combinators which automate the tupling/un-tupling.
-- http://www.latrobe.edu.au/philosophy/phimvt/joy/j00rat.html

main = process2 test

process2 = baz . bar . dup . foo

foo = mul . (push 2) . mul

bar = rep . swap . (push 'A')

test = (2,(3,()))::(Int,(Int,()))

dup (a,b) = (a,(a,b))
swap (a,(b,c)) = (b,(a,c))
push a b = (a,b)

lift1 f (a,b) = (f a,b)
lift2 f (a,(b,c)) = (f a b,c)

len = lift1 length