data NestedList a = Atom a | List [NestedList a] nl = List [Atom 1, Atom 2, List [Atom 3, Atom 4, Atom 5], Atom 6, Atom 7] data RTree a = RNode a [RTree a] deriving Show getVal (RNode x _) = x compute a b (Atom x) = RNode (b x) [] compute a b (List l) = RNode (a $ map getVal computed) $ computed where computed = map (compute a b) l -- compute sum id nl minmax f (x:xs) = foldr f x xs params nl = ( getVal $ compute (minmax min) id nl, getVal $ compute (minmax max) id nl, getVal $ compute ((+1) . (minmax max)) (const 0) nl) t1 (a, _, _) = a t2 (_, a, _) = a t3 (_, _, a) = a params2 :: (Num c, Ord t, Ord c) => NestedList t -> (t, t, c) params2 = getVal . compute (\results -> ( minmax min $ map t1 results, minmax max $ map t2 results, (minmax max $ map t3 results) + 1 )) (\x -> (x, x, 0))