From: Alain Frisch <frisch@clipper.ens.fr>
To: Norman Ramsey <nr@eecs.harvard.edu>
Cc: caml-list@inria.fr
Subject: Re: OCaml and tail recursion
Date: Tue, 14 Dec 1999 16:32:40 +0100 (MET) [thread overview]
Message-ID: <Pine.GSO.4.04.9912141621510.845-100000@clipper> (raw)
In-Reply-To: <199912131727.MAA20344@labrador.eecs.harvard.edu>
On Mon, 13 Dec 1999, Norman Ramsey wrote:
> [snip]
> Apparently ocamlc doesn't optimize tail calls.
Yes it does. It is difficult to help if you don't give the code or its
structure. If you build a list with the characters you parse, consider
rewriting a code like :
let rec map f = function
| h::t -> (f h)::(m f t)
| _ -> []
(which is not tail recursive)
into something like:
let rec map f l =
let rec aux accu = function
| h::t -> aux ((f h)::accu) t
| _ -> []
in
List.rev (aux [] l)
(List.rev is tail recursive)
Alain
next prev parent reply other threads:[~1999-12-14 17:29 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
1999-12-13 17:27 Norman Ramsey
1999-12-14 8:20 ` Xavier Leroy
1999-12-14 15:32 ` Alain Frisch [this message]
1999-12-14 21:20 ` Jerome Vouillon
1999-12-15 14:10 ` Jean-Francois Monin
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=Pine.GSO.4.04.9912141621510.845-100000@clipper \
--to=frisch@clipper.ens.fr \
--cc=caml-list@inria.fr \
--cc=nr@eecs.harvard.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