[MLton] callcc and space use

Vesa Karvonen vesa.a.j.k at gmail.com
Wed Jan 23 07:16:54 PST 2008


On Jan 23, 2008 3:03 PM, Daniel Spoonhower <spoons at cs.cmu.edu> wrote:
[...]
> I attached a small(-ish) example.  It copies and reverses a list of
> reals.  Toward the end of execution there are more than 4000 live cons
> cells in the heap, though the length of the input list is only 75.

BTW, how did you get the numbers?

Glancing at the programs, I quickly spotted one place where you might
have a "leak" (I don't yet understand the whole program), and this
differs between the two versions of the program you sent.  First the
possibly leaky version:

<--- from simple.sml --->
  fun loop () =
      let
        val w = deq ()
        val () = w ()
            handle Continue ws => (app enq ws; loop ())
      in
        loop ()
      end
<--- from simple.sml --->

Consider the two calls to loop () above carefully.  (Note that the
first one of the calls isn't at a tail position.)

Here is the non-leaky version:

<--- from simple2.sml --->
  fun loop () =
      let
        val w = deq ()
        val () = w ()
            handle Continue => ()
      in
        loop ()
      end
<--- from simple2.sml --->

Here the only call to loop () is at a tail position.

In case you haven't already, reading
http://mlton.org/References#BentonKennedy01 might be interesting.

-Vesa Karvonen



More information about the MLton mailing list