Naming and subexpressions

Ketil Z. Malde ketil@ii.uib.no
08 May 2003 11:31:30 +0200


Hi,

I have a program, structured approximately like so

   main =3D do
        let stage1 =3D e1...
        let stage2 =3D e2...stage1...
        stage3 <- e3...stage2
        case something of
                foo -> output stage1
                bar -> output stage2
                baz -> output stage3

I think this is an improvement from using multiple main functions,
since it reveals the pipeline structure of the program and the
modularity of the stages.

It appears=B9, however, that naming the result of stage1 prevents it from
being garbage collected when subsequent stages are produced.  Since
stage1 is a huge list, this leads to a space leak.

So, is there any way to avoid this?  Do I need to restructure my
program?  I could conceivably do

   main =3D do
        let stage1 =3D e1...
        let stage2 =3D e2...(e1...)...
        :

and so on, but an aggressive (but slightly dumb) compiler might
rediscover the similarity and CSE it.

Suggestions more than welcome.

-kzm

=B9 Memory retainer profiling shows the product being retained by
SYSTEM, so I *think* this is the right interpretation.
--=20
If I haven't seen further, it is by standing in the footprints of giants
_______________________________________________
Glasgow-haskell-users mailing list
Glasgow-haskell-users@haskell.org
http://www.haskell.org/mailman/listinfo/glasgow-haskell-users