From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id TAA14516; Thu, 12 Dec 2002 19:15:45 +0100 (MET) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: (from weis@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id TAA14899 for caml-list@pauillac.inria.fr; Thu, 12 Dec 2002 19:15:45 +0100 (MET) Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id GAA27359 for ; Thu, 12 Dec 2002 06:46:49 +0100 (MET) Received: from main.gmane.org (main.gmane.org [80.91.224.249]) by concorde.inria.fr (8.11.1/8.11.1) with ESMTP id gBC5knX20429 for ; Thu, 12 Dec 2002 06:46:49 +0100 (MET) Received: from list by main.gmane.org with local (Exim 3.35 #1 (Debian)) id 18MMB9-0005VL-00 for ; Thu, 12 Dec 2002 06:46:35 +0100 To: caml-list@inria.fr X-Injected-Via-Gmane: http://gmane.org/ Received: from news by main.gmane.org with local (Exim 3.35 #1 (Debian)) id 18MMB8-0005V3-00 for ; Thu, 12 Dec 2002 06:46:34 +0100 Path: not-for-mail From: "=?iso-8859-1?q?Micha=EBl_Gr=FCnewald?=" Subject: [Caml-list] Re: Continuations Date: 12 Dec 2002 06:51:53 +0100 Organization: (none) Message-ID: <87bs3rlr7q.fsf@ketanu.dyndns.org> References: <20021210184936.GA9279@mrtall.compsoc.man.ac.uk> NNTP-Posting-Host: amontpellier-203-1-2-150.abo.wanadoo.fr Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit X-Trace: main.gmane.org 1039671994 21144 80.14.10.150 (12 Dec 2002 05:46:34 GMT) X-Complaints-To: usenet@main.gmane.org NNTP-Posting-Date: Thu, 12 Dec 2002 05:46:34 +0000 (UTC) User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.2 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk Ceri Storey writes: > I was just wondering if there any possibility of there being support > for continuations in a future version of ocaml? Are not they possible ? If i remember well (i did not check it back), the following sample do what is called `Programming with rupture and continuation' (i learned it from J. Chazarin "Programmer avec Scheme"). Help me: just after the "resoud_probleme" definition, you can spot ";;", the i can not achieve to remove (i got a syntax error, then). ---- BEGIN CODE ---- type strategie = Abandonne | Ignore | Remplace of int exception Rupture of (strategie -> int) let resoud_probleme l = let rec continue ax togo strategy = match strategy with | Abandonne -> ax | Ignore -> resoud ax (List.tl togo) | Remplace x -> resoud ax (x::(List.tl togo)) and resoud ax l = match l with | [] -> ax | 0::tl -> raise (Rupture (continue ax l)) | hd::tl -> resoud (ax + hd) tl in resoud 0 l ;; let process_problem l s = try resoud_probleme l with Rupture closure -> closure s in let strategie_to_string s = match s with | Abandonne -> "Abandonne" | Ignore -> "Ignore" | Remplace x -> Printf.sprintf "Remplace par %d" x in let monitor_problem l s = Printf.printf "Solution: %d (%s)\n" (process_problem l s) (strategie_to_string s) in let main () = let pblm = [10; 23; 33; 0; 12] in List.iter (monitor_problem pblm) [Abandonne; Ignore; Remplace 1; Remplace 12]; exit 0 in main() ---- END CODE ---- This code is in the awful French/English mix i write when programming, there is a little lexicon by the end of this message. Maybe this is not what you call Rupture/Cotninuation (you did not speak of rupture), but after my memories, this is. Code explanation: `resoud_problem' must process an horrific and very looong calculous (the sum of 5 or 6 integers from a list), but take the occurence of '0' as a critical situation where the calculous cannot be resumed in a consistent way, it asks the users which Strategy to apply (give up, ignore critical value, correct the value). Lexicon : Abandonne : give up Ignore : ignore (it could have been 'remove') Remplace : replace -- Michaël Grünewald - RSA PGP Key ID: 0x20D90C12 ------------------- To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/ Beginner's list: http://groups.yahoo.com/group/ocaml_beginners