From: Jonathan Roewen <jonathan.roewen@gmail.com>
To: OCaml <caml-list@yquem.inria.fr>
Subject: [Caml-list] HOFs, recursion, and being tail-rec...
Date: Mon, 13 Feb 2006 11:08:16 +1300 [thread overview]
Message-ID: <ad8cfe7e0602121408q15124406ta0e3a42a69c0abcc@mail.gmail.com> (raw)
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 -> ('a * 'a) list -> 'a list -> 'a list
(* I think that's right type: returns positions we can traverse to,
omitting nodes we've previously visited *)
(* val dfs: 'a -> 'a -> ('a * 'a) list -> 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
next reply other threads:[~2006-02-12 22:08 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-02-12 22:08 Jonathan Roewen [this message]
2006-02-12 23:53 ` Jacques Garrigue
2006-02-13 2:05 ` skaller
2006-02-13 2:47 ` Jonathan Roewen
2006-02-13 3:23 ` skaller
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=ad8cfe7e0602121408q15124406ta0e3a42a69c0abcc@mail.gmail.com \
--to=jonathan.roewen@gmail.com \
--cc=caml-list@yquem.inria.fr \
/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