Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
From: Christophe Raffalli <Christophe.Raffalli@univ-savoie.fr>
To: brogoff@speakeasy.net
Cc: Andrew Kennedy <akenn@microsoft.com>,
	Brian Hurt <brian.hurt@qlogic.com>,
	Ocaml Mailing List <caml-list@inria.fr>
Subject: Re: [Caml-list] @, List.append, and tail recursion
Date: Thu, 30 Jan 2003 10:57:10 +0100	[thread overview]
Message-ID: <3E38F6F6.7000206@univ-savoie.fr> (raw)
In-Reply-To: <Pine.LNX.4.44.0301291736260.13213-100000@grace.speakeasy.net>

[-- Attachment #1: Type: text/plain, Size: 2722 bytes --]

brogoff@speakeasy.net wrote:
> Thanks for the reference. I get nailed by this a couple of times a 
> year, and I usually just blame myself for being sloppy and recode 
> all of my maps, appends, and filters to remove it. I think it would 
> be great if those three functions (at least) could be tail recursive, 
> either by having the compiler do it or by providing these "hole 
> abstractions" in the language. 
> 
> I wonder, like the other Brian, if there are existing ML compilers which 
> implement this optimization, and if there is any chance we'll see this in 
> OCaml?
> 
> On Fri, 24 Jan 2003, Andrew Kennedy wrote:

To compute append l1 l2 in a tail recursive way the only solution I see 
(in a pure functionnal program) is to traverse l1 twice (to reverse it 
first), which replaces using memory on the stack by using memory to 
build an intermediate list (and this use more memory ?).

Usually in recursive program, when you limit youself to tail recursive 
function, you have often to reverse list and lisp languages always 
provide the rev_append function which is tail recursive and very often 
what you need (often l1 is an accumulator and is naturaly reversed 
compared with l2).

May be rev_append could be added to the list module (despite the fact it 
is trivial to write it yoursleft) ?


>>Brian,
>>
>>The optimization you describe is sometimes known as
>>"tail modulo cons", and is an example of "destination-passing
>>style". In other words, the place to put the result (in
>>this case, the address of the tail of a just-constructed 
>>cons cell) is passed on in a tail-recursive call.
>>
>>See "A Functional Representation of Data Structures with a Hole"
>>by Minamide in POPL'98.
>>
>>http://www.score.is.tsukuba.ac.jp/~minamide/index.html
>>
>>Although Minimide formalizes the problem in the context of
>>a typed intermediate language, it's probably quite easy to 
>>spot special cases quite far down the compiler pipeline.
>>- Andrew.
>>
>>
>>>-----Original Message-----
>>
> [...snip...]
> 
> -------------------
> 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

-- 
Christophe Raffalli
Université de Savoie
Batiment Le Chablais, bureau 21
73376 Le Bourget-du-Lac Cedex

tél: (33) 4 79 75 81 03
fax: (33) 4 79 75 87 42
mail: Christophe.Raffalli@univ-savoie.fr
www: http://www.lama.univ-savoie.fr/~RAFFALLI
---------------------------------------------
IMPORTANT: this mail is signed using PGP/MIME
At least Enigmail/Mozilla, mutt or evolution
can check this signature
---------------------------------------------

[-- Attachment #2: Type: application/pgp-signature, Size: 252 bytes --]

  reply	other threads:[~2003-01-31  9:34 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-01-24 15:35 Andrew Kennedy
2003-01-30  1:44 ` brogoff
2003-01-30  9:57   ` Christophe Raffalli [this message]
2003-01-30 16:03     ` Brian Hurt
2003-01-31 10:33     ` Mattias Waldau
  -- strict thread matches above, loose matches on Subject: below --
2003-01-31 22:27 Harrison, John R
2003-01-31 19:58 Harrison, John R
2003-01-31 21:04 ` Brian Hurt
2003-01-31 17:32 Diego Olivier Fernandez Pons
2003-01-24  0:48 Brian Hurt
2003-01-30 18:10 ` Olivier Andrieu
2003-01-30 19:46   ` Brian Hurt
2003-01-30 20:52     ` Olivier Andrieu
2003-01-30 21:57       ` Brian Hurt
2003-01-31  2:16         ` james woodyatt
2003-01-31 17:05           ` Diego Olivier Fernandez Pons
2003-01-31 19:52             ` Brian Hurt
2003-01-31 21:34             ` Issac Trotts
2003-01-31 17:13           ` Brian Hurt
2003-01-31 17:42             ` brogoff
2003-01-31 19:18             ` Russ Ross
2003-01-31 19:32               ` Alexander V. Voinov
2003-02-01  2:30               ` brogoff
2003-01-31 23:12             ` Issac Trotts

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=3E38F6F6.7000206@univ-savoie.fr \
    --to=christophe.raffalli@univ-savoie.fr \
    --cc=akenn@microsoft.com \
    --cc=brian.hurt@qlogic.com \
    --cc=brogoff@speakeasy.net \
    --cc=caml-list@inria.fr \
    /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