Why is there a space leak here? (fwd)
Malcolm Wallace
Malcolm.Wallace@cs.york.ac.uk
Thu, 7 Jun 2001 12:11:12 +0100
Hi Claus,
I've had a look at this example in GHood, and you are right, nhc98
does seem to create several copies of v-in.
> import Observe
>
> foo1 m
> = take m (observe "v-out" v)
> where
> v = 1 : concat (map triple (observe "v-in" v))
> triple x = [x,x,x]
>
> main = printO $ (foo1 100::[Int])
> Perhaps Malcolm can explain what nhc98 does with this example?
At a guess, I think the answer lies in lambda-lifting.
nhc98 -c Leak.hs +CTS -lift -CTS
shows this code for `v' (reformatted a little to make it easier to read):
Main.Prelude.173.v = \ v223 v224 ->
Prelude.:
(Prelude._apply1 (Prelude.fromInteger v223) 1L)
(Prelude._apply1
(Prelude.concat)
(Prelude.map (Main.Prelude.174.triple)
(Observe.observe (Observe.Observable.Prelude.[] v224)
(LAMBDA225)
(Prelude._apply2
(Main.Prelude.173.v) v223 v224))))
v takes two arguments; v223 represents the numeric dictionary, and
v224 the Observer dictionary. The recursive reference to v is not
a cyclic pointer to a constant structure, but actually a function call.
I believe the real culprit is that nhc98 does not implement the
monomorphism restriction. IIRC, the DMR applies to every group
of simple pattern bindings at the same let-bound scope, not just
the top-level, so really we ought to default-away the dictionaries,
which would solve this particular space oddity.
Regards,
Malcolm