caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: "Till Varoquaux" <till.varoquaux@gmail.com>
To: "Thomas Fischbacher" <Thomas.Fischbacher@physik.uni-muenchen.de>
Cc: mboconnor@acm.org, caml-list@yquem.inria.fr
Subject: Re: [Caml-list] recursive or loop
Date: Wed, 8 Mar 2006 23:10:24 +0100	[thread overview]
Message-ID: <9d3ec8300603081410p163053e6j8435270a504daf7d@mail.gmail.com> (raw)
In-Reply-To: <Pine.LNX.4.63.0603082255040.26187@eiger.cip.physik.uni-muenchen.de>

On 3/8/06, Thomas Fischbacher <Thomas.Fischbacher@physik.uni-muenchen.de> wrote:
>
> On Wed, 8 Mar 2006, Matthew O'Connor wrote:
>
> > > No it does not. But never mind. It would not help either.
> >
> > Doesn't CPS enable you to basically keep the entire call stack (or
> > equivalent) in the heap?
>
> Yes, it does.
>
> >  Can you explain why it wouldn't help?  Thanks.
>
> You still would have to write out a closure if you want to write all the
> state to disk.

I beleive specifying Marshal.Closures when marshalling should do the trick...

Another way to get along with suspending resuming is by marshalling a
continuation. You can use Xavier Leroy's callcc library and see if
this works out you (just call suspend when you went to exit with a
save point):

open Callcc
open Netchannels
open Marshal

let suspend ()=
  let save_state k=
    let pipe = new Netencoding.Base64.encoding_pipe() in
    with_out_obj_channel
      (new output_channel (open_out "state"))
      (fun ch ->
         let ch' = new output_filter pipe ch in
         ch' # output_string(to_string k [Closures]);
         ch' # close_out()
      );
    (* Skips a warning because this function does not return (it is an exit
       point)*)
    ignore(exit 0)
  in
  callcc save_state
(*
  Saves the "state" the application is in as an base64 encoded marshalled
  continuation.
*)
let _ =
  if (Sys.file_exists "state") then
    let res =
      (let pipe = new Netencoding.Base64.decoding_pipe() in
       with_in_obj_channel
         (new input_channel (open_in "state"))
         (fun ch ->
            let ch' = new input_filter ch pipe in
            let s = string_of_in_obj_channel ch' in
            s
         )) in
    Sys.remove("state");
    let k=Marshal.from_string res 0 in
      throw k ()

Although this has worked callcc is a proof of concept so be ready to
have some nasty bugs... (I've had weird segfaults for instance).
Cheers,
Till

> --
> regards,               tf@cip.physik.uni-muenchen.de              (o_
>  Thomas Fischbacher -  http://www.cip.physik.uni-muenchen.de/~tf  //\
> (lambda (n) ((lambda (p q r) (p p q r)) (lambda (g x y)           V_/_
> (if (= x 0) y (g g (- x 1) (* x y)))) n 1))                  (Debian GNU)
>
> _______________________________________________
> Caml-list mailing list. Subscription management:
> http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list
> Archives: http://caml.inria.fr
> Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
> Bug reports: http://caml.inria.fr/bin/caml-bugs
>


  reply	other threads:[~2006-03-08 22:10 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-03-06 17:25 Jonathan Harrop
2006-03-06 18:25 ` Michael Wohlwend
2006-03-06 18:31   ` Thomas Fischbacher
2006-03-08 19:07     ` Matthew O'Connor
2006-03-08 21:56       ` Thomas Fischbacher
2006-03-08 22:10         ` Till Varoquaux [this message]
2006-03-08 22:13           ` Thomas Fischbacher
2006-03-08 23:28             ` Jon Harrop
2006-03-06 19:25   ` Anil Madhavapeddy
2006-03-06 21:22     ` Michael Wohlwend
2006-03-07 16:02       ` Alan Falloon
2006-03-08  7:53         ` Michael Wohlwend
  -- strict thread matches above, loose matches on Subject: below --
2006-03-06 13:33 Jonathan Harrop
2006-03-06 14:15 ` Thomas Fischbacher
2006-03-06 16:42   ` Michael Wohlwend

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=9d3ec8300603081410p163053e6j8435270a504daf7d@mail.gmail.com \
    --to=till.varoquaux@gmail.com \
    --cc=Thomas.Fischbacher@physik.uni-muenchen.de \
    --cc=caml-list@yquem.inria.fr \
    --cc=mboconnor@acm.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).