On May 13, 4:00 pm, OGrandeDiEnne <[email protected]> wrote:
> On May 13, 2:12 pm, Chris King <[email protected]> wrote:

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


In the non-tail version the backtrack information is stacked  as a
parameter in the call stack, while in the tail version it is inside
the environment of the second argument function.
I don't know how it is compiled the building of the second argument: i
think the cost is analogue to inserting elements in a list.

Since using the call stack is more expensive than a simple push/pop, i
would say that the second implementation is faster.

But of course it depends on how they are actually compiled.

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

Reply via email to