[Haskell-cafe] Seeking advice on a style question

Brian Hulley brianh at metamilk.com
Thu Dec 28 01:53:42 EST 2006


Steve Schafer wrote:
> In my text/graphics formatting work, I find myself doing a lot of
> "pipeline" processing, where a data structure will undergo a number of
> step-by-step transformations from input to output. For example, I
> have a function that looks like this (the names have been changed to
> protect the innocent--and to focus on the structure):
>
>  process :: a -> b -> c -> d -> e
>  process x1 x2 x3 x4 =
>    let y01       = f01 x1 x2 x3;
>        y02       = f02 x1;
>        y03       = f03 y02;
>        y04       = f04 y03;
>        y05       = f05 x1 y01 y04;
>        y06       = f06 x2 y05;
>        (y07,y08) = f07 y01 y06;
>        y09       = f08 y07;
>        (y10,y11) = f09 x2 x4 y09 y08;
>        y12       = f10 y10;
>        y13       = f11 y12;
>        y14       = f12 x1 x2 x3 y01 y13;
>        y15       = f13 y14;
>        y16       = f14 y15 y11
>        in y16

Disclaimer: just re-written by hand so needs double-checking before use:

    process x1 x2 x3 x4 =
        let
            y01 = f01 x1 x2 x3
            (y07, y08) = f07 y01 (f06 x2 (f05 x1 y01 (f04 (f03 y02))))
            (y10, y11) = f09 x2 x4 (f08 y07) y08
        in
            f14 (f13 (f12 x1 x2 x3 y01 (f11 (f10 y10)))) y11

You can also make it look more like the diagram by using more indentation 
eg:

    process x1 x2 x3 x4 =
        let
            y01 =
                f01
                        x1
                        x2
                        x3
            (y07, y08) =
                f07
                        y01
                        (f06
                            x2
                            (f05
                                    x1
                                    y01
                                    (f04
                                        (f03
                                            y02))))
            ...

Best regards, Brian.
-- 
http://www.metamilk.com 



More information about the Haskell-Cafe mailing list