A library for navigating and updating immutable trees. The elements in the tree must have the same type. The trees are implemented in a Huet Zipper fashion.
A list of Contexts that is contructed as a MultiwayTree is navigated. Breadcrumbs are used to retain information about parts of the tree that move out of focus. As the tree is navigated, the needed Context is pushed onto the list Breadcrumbs, and they are maintained in the reverse order in which they are visited
A structure to keep track of the current Tree, as well as the Breadcrumbs to allow us to continue navigation through the rest of the tree.
Move down relative to the current Zipper focus. This allows navigation from a parent to it's children.
(&>) = flip Maybe.andThen
simpleTree =
Tree "a"
[ Tree "b" []
, Tree "c" []
, Tree "d" []
]
Just (simpleTree, [])
&> goToChild 1Move up relative to the current Zipper focus. This allows navigation from a child to it's parent.
(&>) = flip Maybe.andThen
simpleTree =
Tree "a"
[ Tree "b" []
, Tree "c" []
, Tree "d" []
]
Just (simpleTree, [])
&> goToChild 0
&> goUpMove to the root of the current Zipper focus. This allows navigation from any part of the tree back to the root.
(&>) = flip Maybe.andThen
simpleTree =
Tree "a"
[ Tree "b"
[ Tree "e" [] ]
, Tree "c" []
, Tree "d" []
]
Just (simpleTree, [])
&> goToChild 0
&> goToChild 1
&> goToRootMove left relative to the current Zipper focus. This allows navigation from a child to it's previous sibling.
(&>) = flip Maybe.andThen
simpleTree =
Tree "a"
[ Tree "b" []
, Tree "c" []
, Tree "d" []
]
Just (simpleTree, [])
&> goToChild 1
&> goLeftMove right relative to the current Zipper focus. This allows navigation from a child to it's next sibling.
(&>) = flip Maybe.andThen
simpleTree =
Tree "a"
[ Tree "b" []
, Tree "c" []
, Tree "d" []
]
Just (simpleTree, [])
&> goToChild 1
&> goRightMoves to the next node in the hierarchy, depth-first. If already at the end, stays there.
(&>) = flip Maybe.andThen
simpleTree =
Tree "a"
[ Tree "b" []
, Tree "c" []
, Tree "d" []
]
Just (simpleTree, [])
&> goToNext
&> goToNextMoves to the previous node in the hierarchy, depth-first.
(&>) = flip Maybe.andThen
simpleTree =
Tree "a"
[ Tree "b" []
, Tree "c" []
, Tree "d" []
]
Just (simpleTree, [])
&> goToChild 2
&> goToPrevious
&> goToPreviousMove down and as far right as possible relative to the current Zipper focus. This allows navigation from a parent to it's last child.
(&>) = flip Maybe.andThen
simpleTree =
Tree "a"
[ Tree "b" []
, Tree "c" []
, Tree "d" []
]
Just (simpleTree, [])
&> goToRightMostChildMove the focus to the first element for which the predicate is True. If no such element exists returns Nothing. Starts searching at the root of the tree.
(&>) = flip Maybe.andThen
simpleTree =
Tree "a"
[ Tree "b"
[ Tree "e" [] ]
, Tree "c" []
, Tree "d" []
]
Just (simpleTree, [])
&> goTo (\elem -> elem == "e")Update the datum at the current Zipper focus. This allows changes to be made to a part of a node's datum information, given the previous state of the node.
(&>) = flip Maybe.andThen
simpleTree =
Tree "a"
[ Tree "b"
[ Tree "e" [] ]
, Tree "c" []
, Tree "d" []
]
Just (simpleTree, [])
&> goToChild 0
&> updateDatum (\old -> old ++ "X") -- Appends an X to "b"
&> goToRootReplace the datum at the current Zipper focus. This allows complete replacement of a node's datum information, ignoring the previous state of the node.
(&>) = flip Maybe.andThen
simpleTree =
Tree "a"
[ Tree "b"
[ Tree "e" [] ]
, Tree "c" []
, Tree "d" []
]
Just (simpleTree, [])
&> goToChild 0
&> replaceDatum "X" -- Replaces "b" with "X"
&> goToRootInserts a Tree as the first child of the Tree at the current focus. Does not move the focus.
Inserts a Tree as the last child of the Tree at the current focus. Does not move the focus.
Fully replace the children at the current Zipper focus.
Access the datum at the current Zipper focus.
Access the datum at the current Zipper focus as a Maybe.
The Zipper, Gerard Huet Learn You A Haskell, Zippers, Miran Lipovaca
Might be able to integrate existing Rose Tree to work with the Zipper. Wanted the first version to be self contained.
The necessary information needed to reconstruct a MultiwayTree as it is navigated with a Zipper. This context includes the datum that was at the previous node, a list of children that came before the node, and a list of children that came after the node.