From: "Michaël Grünewald" <michael-grunewald@wanadoo.fr>
To: caml-list@inria.fr
Subject: [Caml-list] Re: Continuations
Date: 12 Dec 2002 06:51:53 +0100 [thread overview]
Message-ID: <87bs3rlr7q.fsf@ketanu.dyndns.org> (raw)
In-Reply-To: <20021210184936.GA9279@mrtall.compsoc.man.ac.uk>
Ceri Storey <cez@mrtall.compsoc.man.ac.uk> 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 <michael-grunewald@wanadoo.fr> - 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
next prev parent reply other threads:[~2002-12-12 18:15 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2002-12-10 18:49 [Caml-list] Continuations Ceri Storey
2002-12-11 1:43 ` [Caml-list] Site down Eric Merritt
2002-12-11 9:19 ` [Caml-list] Continuations Christophe Raffalli
2002-12-12 5:51 ` Michaël Grünewald [this message]
2002-12-15 17:06 ` [Caml-list] Continuations: an implementation Christophe Raffalli
2002-12-16 13:36 [Caml-list] Re: Continuations Diego Olivier Fernandez Pons
2002-12-16 18:53 ` Pal-Kristian Engstad
2002-12-17 7:58 ` james woodyatt
2002-12-17 13:50 ` Diego Olivier Fernandez Pons
2002-12-17 8:13 ` james woodyatt
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=87bs3rlr7q.fsf@ketanu.dyndns.org \
--to=michael-grunewald@wanadoo.fr \
--cc=caml-list@inria.fr \
/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