Hi,

Thanks to Miguel for pointing out my silly error. So at least my
understanding of tail recursion is correct :) So then the question
becomes: what *is* the best way to write this function? One version I
can think of is

> ecount :: [Tree] -> Integer -> Integer
> ecount []                  acc = acc
> ecount (Leaf _       : ts) acc = ecount ts $! (acc + 1)
> ecount (Branch t1 t2 : ts) acc = ecount (t1 : t2 : ts) acc

which essentially maintains an explicit stack and runs on all trees. Are
there better ways to do this?

Thanks again and sorry for my mistake,

Edsko
_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to