[Haskell-cafe] Understanding tail recursion and trees
Miguel Mitrofanov
miguelimo38 at yandex.ru
Thu May 1 08:24:29 EDT 2008
Copy-paste approach's failed you. Hint: try removing acountL
definition and compiling everything else.
>> -- count with tail calls for the left subtree
>> acountL :: Tree -> Integer -> Integer
>> acountL (Leaf _) acc = acc + 1
>> acountL (Branch t1 t2) acc = acountL t1 $! (acountL t2 acc)
>>
>>
>> -- count with tail calls for the right subtree
>> acountR :: Tree -> Integer -> Integer
>> acountR (Leaf _) acc = acc + 1
>> acountR (Branch t1 t2) acc = acountR t2 $! (acountL t1 acc)
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
More information about the Haskell-Cafe
mailing list