* callcc/throw...
@ 1999-03-01 17:04 Sussillo, David
1999-03-02 13:06 ` callcc/throw Christophe Raffalli
0 siblings, 1 reply; 2+ messages in thread
From: Sussillo, David @ 1999-03-01 17:04 UTC (permalink / raw)
To: caml-list
Hello,
Is there an OCaml equivalent to the continuation primitives callcc/throw
found in SML/NJ or anything that approximates their behavior?
Maybe someone has a suggestion how I could implement callcc/throw myself
as C calls?
Thanks,
dave
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: callcc/throw...
1999-03-01 17:04 callcc/throw Sussillo, David
@ 1999-03-02 13:06 ` Christophe Raffalli
0 siblings, 0 replies; 2+ messages in thread
From: Christophe Raffalli @ 1999-03-02 13:06 UTC (permalink / raw)
To: Sumlssillo, David, caml-list
If you really need callcc/throw (that is try ... with ... is not enough), this
means you are implementing an algorithm which is bactracking. callcc needs to
save the current stack. this is not very hard as you can copy only the first
page of the stack and delay the other copy when needed. However this keeps a
lot of pointer and will often leads to a lot of memory leaks.
Indeed the stack may contains value that are not related to your backtracking
or that could be recomputed easely.
It is often better (not always) to directly implement your algorithm with the
bactracking explicit (that is keeping a stack of state from which you can
backtrack).
The code is often more difficult to write (you are doing a CPS translation by
hand) but you can gain a lot by
- keeping only what is needed in the state
- not keeping the state from which you know you do not need to backtrack
(most of the time you have a lot of these which are preserved in the stack if
you use callcc)
Christophe Raffalli
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~1999-03-02 17:09 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1999-03-01 17:04 callcc/throw Sussillo, David
1999-03-02 13:06 ` callcc/throw Christophe Raffalli
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox