<?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/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..."
  prev="2006/02/962385fdb164edd1ed6b71a33b90aec6"
  next="2006/02/a45690b88065de88ec908956c5350120"
  next-in-thread="2006/02/a45690b88065de88ec908956c5350120"
  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>
Hi,

I have a simple implementation of depth-first-search, and was
wondering if my approach would qualify as tail-rec (whether from the
code it is/isn't, and whether ocaml can optimise it so it is).

val positions : 'a -&gt; ('a * 'a) list -&gt; 'a list -&gt; 'a list
(* I think that's right type: returns positions we can traverse to,
omitting nodes we've previously visited *)

(* val dfs: 'a -&gt; 'a -&gt; ('a * 'a) list -&gt; bool *)
let dfs start goal edges =
    let rec search visited position =
      if position = goal then true
      else List.exists (search (position::visited)) (positions
position edges (position::visited))
    in search [] start;;

Jonathan

</contents>

</message>

