<?xml version="1.0" encoding="ISO-8859-1"?>

<!DOCTYPE message PUBLIC
  "-//MLarc//DTD MLarc output files//EN"
  "../../mlarc.dtd"[
  <!ATTLIST message
    listname CDATA #REQUIRED
    title CDATA #REQUIRED
  >
]>

  <?xml-stylesheet href="../../mlarc.xsl" type="text/xsl"?>


<message 
  url="2006/02/ec0d44ff62d75045f20c72ef969673d9"
  from="skaller &lt;skaller@u...&gt;"
  author="skaller"
  date="2006-02-13T02:05:38"
  subject="Re: [Caml-list] HOFs, recursion, and being tail-rec..."
  prev="2006/02/a74b4211ff6f1c1241c93b24e6b20882"
  next="2006/02/d7f6a535f2b5af686757913f5410d4c3"
  prev-in-thread="2006/02/a45690b88065de88ec908956c5350120"
  next-in-thread="2006/02/d7f6a535f2b5af686757913f5410d4c3"
  prev-thread="2006/02/a51f7a8ac5ce6d0b7ddd632d1c82c550"
  next-thread="2006/02/a74b4211ff6f1c1241c93b24e6b20882"
  root="../../"
  period="month"
  listname="caml-list"
  title="Archives of the Caml mailing list">

<thread subject="[Caml-list] HOFs, recursion, and being tail-rec...">
<msg 
  url="2006/02/20b9bddf6cd70a75c82f40d837c93956"
  from="Jonathan Roewen &lt;jonathan.roewen@g...&gt;"
  author="Jonathan Roewen"
  date="2006-02-12T22:08:17"
  subject="[Caml-list] HOFs, recursion, and being tail-rec...">
<msg 
  url="2006/02/a45690b88065de88ec908956c5350120"
  from="Jacques Garrigue &lt;garrigue@m...&gt;"
  author="Jacques Garrigue"
  date="2006-02-12T23:52:13"
  subject="Re: [Caml-list] HOFs, recursion, and being tail-rec...">
<msg 
  url="2006/02/ec0d44ff62d75045f20c72ef969673d9"
  from="skaller &lt;skaller@u...&gt;"
  author="skaller"
  date="2006-02-13T02:05:38"
  subject="Re: [Caml-list] HOFs, recursion, and being tail-rec...">
<msg 
  url="2006/02/d7f6a535f2b5af686757913f5410d4c3"
  from="Jonathan Roewen &lt;jonathan.roewen@g...&gt;"
  author="Jonathan Roewen"
  date="2006-02-13T02:47:09"
  subject="Re: [Caml-list] HOFs, recursion, and being tail-rec...">
<msg 
  url="2006/02/7671c25a66146a5eacec0fcc2cdb6277"
  from="skaller &lt;skaller@u...&gt;"
  author="skaller"
  date="2006-02-13T03:23:53"
  subject="Re: [Caml-list] HOFs, recursion, and being tail-rec...">
</msg>
</msg>
</msg>
</msg>
</msg>
</thread>

<contents>
On Mon, 2006-02-13 at 08:53 +0900, Jacques Garrigue wrote:
&gt; From: Jonathan Roewen &lt;jonathan.roewen@gmail.com&gt;
&gt; &gt; 
&gt; &gt; I have a simple implementation of depth-first-search, and was
&gt; &gt; wondering if my approach would qualify as tail-rec (whether from the
&gt; &gt; code it is/isn't, and whether ocaml can optimise it so it is).
&gt; 
&gt; By definition a depth-first-search cannot be tail-recursive: you need
&gt; a stack to implement the backtracking.

There is a need for a stack, but it doesn't have to be
a machine (control) stack. A basic principle of duality
seems to be that control and data can always be transformed
into each other (proof: Turing only has conditional goto). 
In this case CPS provides the transform.

There is category error in Jacques claim: depth-first search
is an algorithm, it is a matter of *semantics*.

Tail-rec is merely a *syntactic* property, which has
semantic implications only for a particular implementation.

So it isn't a well formed sentence to say depth first 
search cannot be tail-rec, it is easy to construct a 
depth first search in any FPL that is. 

However, no matter what you do, you will indeed need
memory linear in the tree depth (unless it is 1-ary tree as
pointed out).

BTW: considering control/data duality you will find that most compilers
miss very interesting optimisations. Ackermann's function
can be implemented using only 2 words (for the arguments)
per stack frame. No compilers I know of do this optimisation --
and I have not seen any reference to it in the literature.


-- 
John Skaller &lt;skaller at users dot sf dot net&gt;
Felix, successor to C++: http://felix.sf.net

</contents>

</message>

