caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] Python's yield, Lisp's call-cc or C's setjmp/longjmp in OCaml
@ 2003-12-16 13:13 Nuutti Kotivuori
  2003-12-16 13:28 ` Oleg Trott
                   ` (2 more replies)
  0 siblings, 3 replies; 25+ messages in thread
From: Nuutti Kotivuori @ 2003-12-16 13:13 UTC (permalink / raw)
  To: caml-list

I am wondering, does OCaml provide any variant of being able to
bypass the normal function call and return discipline?

More or less generic implementations of this can be seen in for
example Python's yield instruction, Lisp's call-cc or call with
current continuation, or C's setjmp/longjmp.

And if not, what are the chances of something like that seeing the
light of day in the future? Are there any fundamental problems in
OCaml that would make the implementation of such a thing exceedingly
difficult?

Just curiosity at this point.

-- Naked

-------------------
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


^ permalink raw reply	[flat|nested] 25+ messages in thread
* RE: [Caml-list] Python's yield, Lisp's call-cc or C's setjmp/longjmp in OCaml
@ 2003-12-16 18:06 Kevin S. Millikin
  0 siblings, 0 replies; 25+ messages in thread
From: Kevin S. Millikin @ 2003-12-16 18:06 UTC (permalink / raw)
  To: caml-list

On Tuesday, December 16, 2003 9:42 AM, Kenneth Knowles 
[SMTP:kknowles@uclink.berkeley.edu] wrote:

> SML/NJ is a continuation-passing style compiler, so they are trivial.
> It is "possible, even in the presence of native compilation
> exceptions," but in a traditiional call stack compilation it requires
> some sort of stack copying, making them extremely inefficient.  (in
> SML/NJ every program is slower, while continuations have almost no
> penalty)

> There may be new tricks for avoiding copying of the whole stack, but 
I
> wouldn't hold your breath for continuations in ocaml.

You don't *have* to copy the stack on continuation capture, just mark 
the point where the continuation was captured and seal it off.  You do 
have to copy stack frames (but not the whole stack)---on continuation 
restore or upon stack segment underflow.

Programs that use continuations are (for the most part) the ones that 
pay the price, and they pay that (bounded) price upon continuation 
invocation or returning past a captured continuation.

For details on these new tricks, you can read Hieb, Dybvig, and 
Bruggeman's 1990 PLDI paper.

----
Kevin S. Millikin           Architecture Technology Corporation
Research Scientist          Specialists in Computer Architecture
(952)829-5864 x162          http://www.atcorp.com

-------------------
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


^ permalink raw reply	[flat|nested] 25+ messages in thread
* Re: [Caml-list] Python's yield, Lisp's call-cc or C's setjmp/longjmp in OCaml
@ 2003-12-18 22:08 Ker Lutyn
  0 siblings, 0 replies; 25+ messages in thread
From: Ker Lutyn @ 2003-12-18 22:08 UTC (permalink / raw)
  To: caml-list

How about:

type 'a cont = Cont of ('a -> 'a cont)

let apply c x = match c with Cont f -> f x

let rec iterator c = function
  | Node l -> List.fold_left iterator c l
  | Leaf x -> apply c x

On Thu, Dec 18, 2003 at 10:14:19AM +0900, Nicolas Cannasse wrote:
>
> type 'a tree =
>     |  Node of 'a tree list
>     |  Leaf of 'a
> 
> let rec iterator = function
>     | Node l -> List.iter iterator l
>     | Leaf x -> yield x
> 
> Doing it using a closure is more difficult, since we need to reproduce the
> stack using a data structure. That goes of course for all recursive data
> structures.



__________________________________
Do you Yahoo!?
New Yahoo! Photos - easier uploading and sharing.
http://photos.yahoo.com/

-------------------
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


^ permalink raw reply	[flat|nested] 25+ messages in thread

end of thread, other threads:[~2003-12-19 13:40 UTC | newest]

Thread overview: 25+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-12-16 13:13 [Caml-list] Python's yield, Lisp's call-cc or C's setjmp/longjmp in OCaml Nuutti Kotivuori
2003-12-16 13:28 ` Oleg Trott
2003-12-18  0:15   ` Nuutti Kotivuori
2003-12-16 13:48 ` Ville-Pertti Keinonen
2003-12-16 15:41   ` Kenneth Knowles
2003-12-16 16:45     ` Richard Jones
2003-12-16 18:36       ` Ville-Pertti Keinonen
2003-12-16 18:42 ` Brian Hurt
2003-12-16 18:10   ` Dustin Sallings
2003-12-17  6:30     ` ijtrotts
2003-12-17  8:13       ` Dustin Sallings
2003-12-17 10:35       ` Falk Hueffner
2003-12-17 19:14         ` Pierre Weis
2003-12-17 19:32           ` Falk Hueffner
2003-12-17 20:04           ` David Brown
2003-12-18  1:14           ` Nicolas Cannasse
2003-12-18  5:31             ` David Brown
2003-12-18  7:05             ` Brian Hurt
2003-12-18  6:45               ` David Brown
2003-12-18 18:44             ` brogoff
2003-12-17 19:42         ` brogoff
2003-12-19 13:39           ` skaller
2003-12-18  0:51       ` Nuutti Kotivuori
2003-12-16 18:06 Kevin S. Millikin
2003-12-18 22:08 Ker Lutyn

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).