{-# LANGUAGE UnicodeSyntax #-} module Tuple where data Tree a = Leaf | Node (Tree a) a (Tree a) deriving Show labelTree ∷ Tree a → Tree Int labelTree t = fst $ labelTreeW t 0 labelTreeW ∷ Tree a → Int → (Tree Int, Int) labelTreeW Leaf counter = (Leaf, counter) labelTreeW (Node l _ r) counter = let (l', counterL) = labelTreeW l counter counterN = counterL + 1 (r', counterR) = labelTreeW r counterN in (Node l' counterN r', counterR)