<?xml version="1.0" encoding="ISO-8859-1"?>

<!DOCTYPE message PUBLIC
  "-//MLarc//DTD MLarc output files//EN"
  "../../mlarc.dtd"[
  <!ATTLIST message
    listname CDATA #REQUIRED
    title CDATA #REQUIRED
  >
]>

  <?xml-stylesheet href="../../mlarc.xsl" type="text/xsl"?>


<message 
  url="2002/12/cb2c8e18ae2a70b24a14ec6dfa63f9b0"
  from="Michaël_Grünewald &lt;michael-grunewald@w...&gt;"
  author="Michaël_Grünewald"
  date="2002-12-12T18:15:45"
  subject="[Caml-list] Re: Continuations"
  prev="2002/12/fa5147003546a7ff957dba5a5ab3012d"
  next="2002/12/75b9ca3454812923f0eb7f72e657adfd"
  prev-in-thread="2002/12/17d951b73af6adf7fd25af77db4583f0"
  next-in-thread="2002/12/c6cf5d6a698ddeb08791e29a39e73382"
  prev-thread="2002/12/6e4f1518eb7ad7eee939898ec70eabc8"
  next-thread="2002/12/919e5b9de09938198c2fd0856d238c55"
  root="../../"
  period="month"
  listname="caml-list"
  title="Archives of the Caml mailing list">

<thread subject="[Caml-list] Continuations">
<msg 
  url="2002/12/a7df150482511ac2dc29aad949c1630c"
  from="Ceri Storey &lt;cez@m...&gt;"
  author="Ceri Storey"
  date="2002-12-10T20:28:06"
  subject="[Caml-list] Continuations">
<msg 
  url="2002/12/a76364f857529a996d6c73a20fc6f785"
  from="Eric Merritt &lt;cyberlync@y...&gt;"
  author="Eric Merritt"
  date="2002-12-11T01:43:05"
  subject="[Caml-list] Site down">
</msg>
<msg 
  url="2002/12/17d951b73af6adf7fd25af77db4583f0"
  from="Christophe Raffalli &lt;Christophe.Raffalli@u...&gt;"
  author="Christophe Raffalli"
  date="2002-12-11T09:22:43"
  subject="Re: [Caml-list] Continuations">
</msg>
<msg 
  url="2002/12/cb2c8e18ae2a70b24a14ec6dfa63f9b0"
  from="Michaël_Grünewald &lt;michael-grunewald@w...&gt;"
  author="Michaël_Grünewald"
  date="2002-12-12T18:15:45"
  subject="[Caml-list] Re: Continuations">
<msg 
  url="2002/12/c6cf5d6a698ddeb08791e29a39e73382"
  from="Christophe Raffalli &lt;Christophe.Raffalli@u...&gt;"
  author="Christophe Raffalli"
  date="2002-12-15T21:44:14"
  subject="[Caml-list] Continuations: an implementation">
</msg>
</msg>
</msg>
</thread>

<contents>
Ceri Storey &lt;cez@mrtall.compsoc.man.ac.uk&gt; writes:

&gt; I was just wondering if there any possibility of there being support
&gt; 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 -&gt; int)

let resoud_probleme l =

    let rec continue ax togo strategy =
	match strategy with
	    | Abandonne -&gt; 	ax
	    | Ignore -&gt; 	resoud ax (List.tl togo)
	    | Remplace x -&gt; 	resoud ax (x::(List.tl togo))

    and resoud ax l = 
	match l with 
	    | [] -&gt;	ax
	    | 0::tl -&gt; 	raise (Rupture (continue ax l))
	    | hd::tl -&gt; resoud (ax + hd) tl

    in resoud 0 l
;;

let process_problem l s =
    try  resoud_probleme l
    with Rupture closure -&gt; closure s
    	
in
let strategie_to_string s = 
    match s with
	| Abandonne -&gt; "Abandonne"
	| Ignore -&gt; "Ignore"
	| Remplace x -&gt; 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 &lt;michael-grunewald@wanadoo.fr&gt;  - 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

</contents>

</message>

