Version française
Home     About     Download     Resources     Contact us    
Browse thread
[Caml-list] stack overflow
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Mike Lin <mikelin@M...>
Subject: Re: CPS folds (was Re: [Caml-list] stack overflow)
If y'all want to see a real example, Yaxpo is a whole XML parser 
structured in CPS. One of the things it has to do is, of course, to 
build up a DOM tree.

http://mikelin.mit.edu/yaxpo

-Mike

On Wednesday, April 9, 2003, at 12:54  PM, brogoff@speakeasy.net wrote:

> On Wed, 9 Apr 2003, Neel Krishnaswami wrote:
>> Yang Shouxun writes:
>>> On Wednesday 09 April 2003 16:14, Markus Mottl wrote:
>>>>
>>>> The trick is to use continuation passing style (CPS): you pass a
>>>> function closure (continuation) containing everything that's
>>>> needed in subsequent computations.  Instead of returning a result,
>>>> the sub-function calls the continuation with the result, which
>>>> makes the functions tail-recursive.
>>>
>>> I've learned this style in Scheme. Yet I feel paralyzed when trying
>>> to write in it to build trees. The problems are that unless the next
>>> call returns, the tree is not complete yet and it may have several
>>> calls on itself.
>
> Before going any further, see if you can recompile the program in 
> bytecode, and
> detect the error location using stack tracing.
>
> CPS is not that helpful in cases where you can't find some clever
> defunctionalization of the CPS function into accumulator passing style 
> or
> something else. All those closures that get allocated so that you don't
> hit the stack have a cost, too. Measure before using.
>
> That said, all of this CPS stuff is fascinating, and well worth 
> learning for any
> computing professional with an interest in functional programming. If 
> you know
> Scheme, buy yourself a copy of "Essentials of Programming Languages". 
> There are
> some really great chapters on CPS in that book.
>
> -- Brian
>
>
> -------------------
> 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

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