On May 13, 2:12 pm, Chris King <[email protected]> wrote: > 2) is false; consider for example a function traversing a binary tree. You > need some sort of "breadcrumb" trail to backtrack after visiting left > children. This will always be of the form of some sort of stack or queue, > whether explicit or implicit (implied by non-tail recursion).
let visit tree = match tree with | leaf(v) -> v | node(v,t1,t2) -> let v1 = visit t1 and v2 = visit t2 in v + v1 + v2 let visit_tail tree k = | Leaf(v) -> k v | Node(v,t1,t2) -> visit_tail t1 (fun v1 -> visit_tail t2 (fun v2 -> k( v + v1 + v2 ) )) You said that > This will always be of the form of some sort of stack or queue, > whether explicit or implicit (implied by non-tail recursion). Here the queue is encoded in the chain of anonymous function. How are the two versions actually compiled ? Is the second faster than the first ? -- You received this message because you are subscribed to the Google Groups "ocaml-developer" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/ocaml-developer?hl=en For other OCaml forums, see http://caml.inria.fr/resources/forums.en.html
