From: Mike Lin <mikelin@MIT.EDU>
To: Neel Krishnaswami <neelk@alum.mit.edu>
Cc: "caml-list@inria.fr" <caml-list@inria.fr>
Subject: Re: CPS folds (was Re: [Caml-list] stack overflow)
Date: Wed, 9 Apr 2003 13:23:59 -0400 [thread overview]
Message-ID: <0CFED0CA-6AB0-11D7-AC6E-000393AE4242@mit.edu> (raw)
In-Reply-To: <Pine.LNX.4.44.0304090906160.13117-100000@grace.speakeasy.net>
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
next prev parent reply other threads:[~2003-04-09 17:24 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2003-04-09 2:10 [Caml-list] stack overflow Yang Shouxun
2003-04-09 2:19 ` brogoff
2003-04-09 2:45 ` Yang Shouxun
2003-04-09 8:14 ` Markus Mottl
2003-04-09 9:23 ` Yang Shouxun
2003-04-09 11:34 ` Markus Mottl
2003-04-10 4:12 ` Parallel CPS? (was Re: [Caml-list] stack overflow) Yang Shouxun
2003-04-10 4:58 ` Mike Lin
2003-04-09 14:14 ` CPS folds " Neel Krishnaswami
2003-04-09 16:54 ` brogoff
2003-04-09 17:23 ` Mike Lin [this message]
2003-04-09 2:43 ` [Caml-list] stack overflow David Brown
[not found] ` <200304091034.45256.yangsx@fltrp.com>
[not found] ` <16019.34434.468479.586884@barrow.artisan.com>
2003-04-09 2:53 ` Yang Shouxun
2003-04-09 6:45 ` David Monniaux
2003-04-13 15:42 ` John Max Skaller
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=0CFED0CA-6AB0-11D7-AC6E-000393AE4242@mit.edu \
--to=mikelin@mit.edu \
--cc=caml-list@inria.fr \
--cc=neelk@alum.mit.edu \
/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