Can someone explain the traverse function in Haskell?
I am trying and failing to grok the traverse function from Data.Traversable . I am unable to see its point. Since I come from an imperative background, can someone please explain it to me in terms of an imperative loop? Pseudo-code would be much appreciated. Thanks. traverse is the same as fmap , except that it also allows you to run effects while you're rebuilding the data structure. Take a look at the example from the Data.Traversable documentation. data Tree a = Empty | Leaf a | Node (Tree a) a (Tree a) The Functor instance of Tree would be: instance Functor Tree where fmap f Empty = Empty