License | GNU LGPLv3 |
---|---|
Maintainer | paul.bittner@uni-ulm.de |
Safe Haskell | Safe |
Implementation of a rose tree (i.e., a tree whose nodes can have an arbitrary amount of children, including 0) we use for AST
s .
Synopsis
- data Tree a = Tree a [Tree a]
- isleaf :: Tree a -> Bool
- element :: Tree a -> a
- tree :: (Eq a, Show a) => Tree a -> a -> Tree a
- safetree :: Eq a => Tree a -> a -> Maybe (Tree a)
- toset :: Ord a => Tree a -> Set a
- find :: (Tree a -> Bool) -> Tree a -> Maybe (Tree a)
- findByNode :: (a -> Bool) -> Tree a -> Maybe (Tree a)
- parent :: Eq a => Tree a -> Tree a -> Maybe (Tree a)
- ancestors :: Eq a => Tree a -> Tree a -> [Tree a]
- manipulate :: (Tree a -> Tree a) -> Tree a -> Tree a
- filterTrees :: (Tree a -> Bool) -> Tree a -> Tree a
- filterNodes :: (Tree a -> Bool) -> Tree a -> Tree a
- prettyPrint :: (Show a, Monoid b) => Int -> (String -> b) -> (a -> b) -> Tree a -> b
Documentation
Rose tree of elements of type a where children of nodes are given as lists.
Instances
Functor Tree Source # | |
Applicative Tree Source # | |
Foldable Tree Source # | |
Defined in Tree fold :: Monoid m => Tree m -> m foldMap :: Monoid m => (a -> m) -> Tree a -> m foldMap' :: Monoid m => (a -> m) -> Tree a -> m foldr :: (a -> b -> b) -> b -> Tree a -> b foldr' :: (a -> b -> b) -> b -> Tree a -> b foldl :: (b -> a -> b) -> b -> Tree a -> b foldl' :: (b -> a -> b) -> b -> Tree a -> b foldr1 :: (a -> a -> a) -> Tree a -> a foldl1 :: (a -> a -> a) -> Tree a -> a elem :: Eq a => a -> Tree a -> Bool maximum :: Ord a => Tree a -> a | |
Traversable Tree Source # | |
Eq a => Eq (Tree a) Source # | |
Show a => Show (Tree a) Source # | |
isleaf :: Tree a -> Bool Source #
Returns true iff the given tree is a leaf (i.e., it has no children).
tree :: (Eq a, Show a) => Tree a -> a -> Tree a Source #
Finds a subtree in the given tree (first argument) whose root has the given value (second argument). Throws an error iff no such tree exists.
safetree :: Eq a => Tree a -> a -> Maybe (Tree a) Source #
Same as tree
but returns Nothing
in the error case (i.e., when no subtree contains the given value).
toset :: Ord a => Tree a -> Set a Source #
Transforms a tree into a set. The returned set contains exactly the values previously held in the tree.
find :: (Tree a -> Bool) -> Tree a -> Maybe (Tree a) Source #
Find a subtree in the given tree (first argument) whose root matches the predicate (second argument).
findByNode :: (a -> Bool) -> Tree a -> Maybe (Tree a) Source #
Same as find
but takes a predicate over elements instead of a predicate over trees to identify the subtree of interest.
parent :: Eq a => Tree a -> Tree a -> Maybe (Tree a) Source #
Returns the parent of the given node (second argument) in the given tree (first argument). The returned parent is a subtree of the first given tree and has the second given tree as child. Throws an error iff no parent exists.
ancestors :: Eq a => Tree a -> Tree a -> [Tree a] Source #
Retrieves all nodes that are above the given node (second argument) in the given tree (first argument)
(This is the transitive closure of parent
.)
manipulate :: (Tree a -> Tree a) -> Tree a -> Tree a Source #
Applies the given function to each node from bottom to top (i.e., leaves are converted first, root last).
filterTrees :: (Tree a -> Bool) -> Tree a -> Tree a Source #
Removes all subtrees not meeting the imposed condition. The root remains untouched.
filterNodes :: (Tree a -> Bool) -> Tree a -> Tree a Source #
Removes all nodes not meeting the imposed condition. Children of removed nodes are moved up and become children of the parent of the removed node. The root remains untouched.
prettyPrint :: (Show a, Monoid b) => Int -> (String -> b) -> (a -> b) -> Tree a -> b Source #
Pretty print function that folds the tree into a monoidial type b
.
b
is the type that is the output of the print (e.g., String or Text).
First argument is the length of the indent in spaces (e.g., 2 will produce an indent of " "
per level).
Second argument is a function that lifts strings to the output type b (e.g., a constructor of b
accepting a string).
Third argument is a function to convert tree elements to the output type (e.g., show
if b
is String
).