From: skaller <skaller@users.sourceforge.net>
To: Jonathan Bryant <jtbryant@valdosta.edu>
Cc: caml-list@yquem.inria.fr
Subject: Re: [Caml-list] tail rec
Date: Sun, 20 May 2007 08:13:20 +1000 [thread overview]
Message-ID: <1179612800.6131.2.camel@rosella.wigram> (raw)
In-Reply-To: <E46132AA-7DDA-4686-92DB-9D357210543E@valdosta.edu>
On Sat, 2007-05-19 at 16:19 -0400, Jonathan Bryant wrote:
>
> >>> I have a silly idea. Introduce a new construction:
> >>>
> >>> let tailrec f ..
> >>>
> >>> This is the same as let rec except it checks every direct call to f
> >>> is in tail position (and bombs out the compiler if not).
>
> A question I have about tail recursion in general:
>
> let f x = (* Do something *)
> let g x = (* Do something *); f x
> let h x = (* Do something *); g x
>
> Does the compiler optimize the calls (f x) and (g x) into tail
> calls? If so, how would the
>
> let railrec f x = ...
> let tailrec g x = ...
> let tailrec h x = ...
>
> syntax handle/help this?
let tailrec would be a bad idea here because these
functions aren't recursive. However this form:
let g x = (* Do something *); tail f x
would assure you the call to f is tailed.
--
John Skaller <skaller at users dot sf dot net>
Felix, successor to C++: http://felix.sf.net
next prev parent reply other threads:[~2007-05-19 22:13 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-05-19 2:56 skaller
2007-05-19 5:00 ` [Caml-list] " Erik de Castro Lopo
2007-05-19 5:28 ` Basile STARYNKEVITCH
2007-05-19 12:58 ` skaller
2007-05-19 20:19 ` Jonathan Bryant
2007-05-19 21:55 ` Erik de Castro Lopo
2007-05-19 22:13 ` skaller [this message]
2007-05-19 14:28 ` Oliver Bandel
2007-05-19 14:46 ` Oliver Bandel
2007-05-19 16:06 ` skaller
2007-05-21 12:57 ` Brian Hurt
2007-05-21 13:04 ` Robert Fischer
2007-05-21 13:21 ` Basile STARYNKEVITCH
2007-05-21 13:30 ` Robert Fischer
2007-05-21 14:00 ` Brian Hurt
2007-05-21 13:47 ` Daniel Bünzli
2007-05-21 14:24 ` Christopher L Conway
2007-05-21 14:36 ` Jon Harrop
2007-05-21 14:49 ` Richard Jones
2007-05-21 14:42 ` ocaml faq (was [Caml-list] tail rec) Daniel Bünzli
2007-05-21 15:09 ` Christopher L Conway
2007-05-21 15:17 ` Robert Fischer
2007-05-21 15:27 ` Daniel Bünzli
2007-05-21 16:23 ` Richard Jones
2007-05-21 16:59 ` Robert Fischer
2007-05-21 16:26 ` Richard Jones
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=1179612800.6131.2.camel@rosella.wigram \
--to=skaller@users.sourceforge.net \
--cc=caml-list@yquem.inria.fr \
--cc=jtbryant@valdosta.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