Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
Ask-if-continue wrapper?
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2005-12-28 (08:44)
From: Stephen Brackin <stephen.brackin@v...>
Subject: Ask-if-continue wrapper?
I'd like an OCaml function, which I'll call continueq, with the property
that for any function f with argument(s) fargs,

continueq f fargs tsecs defaultval

starts evaluating f on fargs and lets this evaluation proceed for up to
tsecs seconds. If the computation of (f fargs) completes in this time, then
it returns the result of that computation. Otherwise, it asks the user how
many seconds to let the computation of (f fargs) proceed. If the user inputs
a value less than or equal to 0, then it returns defaultval. If the user
inputs a value tsecs' greater than 0, then it evaluates

continueq f' fargs' tsecs' defaultval

where (f' fargs') denotes the computation state of (f fargs) at the time it
was interrupted.

I want to give the user the option of continuing without having to repeat
earlier calculations. This is similar to the checkpoint utility ckpt, and
similar to the "timeout" function described in the O'Reilly "'Developing
Applications with Objective Caml" reference book, but not quite the same as
either. Will someone please tell me how to do it?