Hi, I’m educating myself and having fun learning about PureScript by reading PureScript by Example.
In the Applicative Validation chapter there’s an exercise to [w]rite a Traversable instance for the following binary tree data structure […] which I did for this structure
data Tree a = Leaf | Branch (Tree a) a (Tree a)
by creating a Traversable instance for this algebraic type. It worked, yay!
The book mentions that [t]his corresponds to an in-order traversal of the tree. I had a tough time figuring out that to create a tree which can be traversed differently (using
traverse) I would need to create a different algeraic structure where I shuffle the order of the position of the left and right subtree and the node’s value in the structures definition.
My question: how would one traverse the above mentioned structure (left subtree, node value, right subtree) in a preorder or any other way (sensibly)?