Haskell - depth for each node in binary tree using Reader monad
I wrote the following code. It is working and using the Reader monad. Could you give me some hints about code style in Haskell ? Mainly, I mean monads -- I am newbie. import Control.Monad.Reader data Tree a = Node a (Tree a) (Tree a) | Empty renumberM :: Tree a -> Reader Int (Tree Int) renumberM (Node _ l r) = ask >>= (\x -> return (Node x (runReader (local (+1) (renumberM l)) x) (runReader (local (+1) (renumberM r)) x))) renumberM Empty = return Empty renumber'' :: Tree a -> Tree Int renumber'' t = runReader (renumberM t) 0 I want to show you that your idea is an instance of a more general