Well, if you could change your data structure, probably something like
this could work (in spirit of Daniil's response):
module Main where
data Tree = Tree {
parent :: Maybe (Either Tree Tree)
, left :: Maybe Tree
, right :: Maybe Tree
}
buildTree :: (a -> (Maybe a, Maybe a)) -> a -> Tree
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)
-- coun
Hi,
I am writing a simple compiler for a small DSL embedded in Haskell, and
am struggling to identify and remove the source of a stack error when
compiling larger examples. To understand the issues better, I was
playing around with tail recursion on trees when I came across the
following problem.