caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* tail rec
@ 2007-05-19  2:56 skaller
  2007-05-19  5:00 ` [Caml-list] " Erik de Castro Lopo
                   ` (3 more replies)
  0 siblings, 4 replies; 26+ messages in thread
From: skaller @ 2007-05-19  2:56 UTC (permalink / raw)
  To: caml-list

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

[Maybe this can be done with camlp4, though I think it might
be hard?]

I think this could be useful for newbies learning functional
programming, and perhaps even experts looking for performance
issues.

If a let closure of f is made, a warning is issued, eg:

let tailrec f x = 
  let g x = f x in (* WARNING *)
  1 + g (x - 1) (* not tail, but not explicit call of f *)

The annotation does NOT prove a function is tail rec,
but if the compiler bombs, it proves the function is
not tail rec.

Comments?

-- 
John Skaller <skaller at users dot sf dot net>
Felix, successor to C++: http://felix.sf.net


^ permalink raw reply	[flat|nested] 26+ messages in thread

end of thread, other threads:[~2007-05-21 16:59 UTC | newest]

Thread overview: 26+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-05-19  2:56 tail rec 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
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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).