Why is there a space leak here? (fwd)
Thu, 7 Jun 2001 12:11:12 +0100
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)
> 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._apply1 (Prelude.fromInteger v223) 1L)
(Observe.observe (Observe.Observable.Prelude. v224)
(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.