[Haskell-beginners] How to move nodes in Data.Tree.Zipper

martin martin.drautzburg at web.de
Sat Jul 9 10:01:12 UTC 2016


Hello all,

I've been playing with Data.Tree.Zipper and one of the tasks I set for myself was to move a node to another position. I
endet up in a situation, where I no longer have a clear understanding what "moving" means.

Data.Tree.Zipper distinguishes between Nodes ("Full") and Space ("Empty"). So I thought to move a nde I need to know the
node to be moved ("Full") and the space where it shall be moved to ("Empty")

But I need to do two things:

(1) remove the node from its original position
(2) insert the node at the empty space given.

Both operations are supported by D.T.Z, but once I removed the node, I have a new Zipper, while the space given still
refers to the original zipper. The new Zipper has no idea where the deleted node shall be inserted and the original
empty space doesn't have the node removed.

This is not the fault of D.T.Z, but in a way a real-world problem I had been unaware of. With my original idea I could
have moved a node to a subspace of itself, which makes no real sense. It appears that giving two zippers to a
tree-modifying function is utterly useless when they refer to the same tree and both undergo modifications by the function.

What would be a correct way to think about this?





More information about the Beginners mailing list