import Base(ana,cata) data Tree a = Leaf a | Bin (Tree a) (Tree a) deriving Show balance :: [a] -> Tree a balance = ana ba ba :: [a] -> FunctorOf Tree a [a] ba xs = case xs of [] -> error "Can't represent the empty list" [x] -> Left x xs -> Right (splitAt (length xs `div` 2) xs) t1 :: Tree Char t1 = balance "Patrik" main :: IO () main = print (t1,depth t1) depth :: Tree a -> Int depth = cata de de :: FunctorOf Tree a Int -> Int de = either (const 0) (\(m,n)-> 1 + max m n)