Implement terminals
This commit is contained in:
@@ -9,6 +9,8 @@ the nodes in the trunk are [a,b] (note that d is not the first child of b).
|
||||
-}
|
||||
module Dodge.Tree.Polymorphic
|
||||
( applyToRoot
|
||||
, applyToSubtree
|
||||
, applyToSubforest
|
||||
, treeFromPost
|
||||
, treeFromTrunk
|
||||
, splitTrunk
|
||||
@@ -56,6 +58,22 @@ applyToNode (i:is) f (Node x xs) = Node x (ys ++ [applyToNode is f z] ++ zs)
|
||||
where
|
||||
(ys, z:zs) = splitAt i xs
|
||||
|
||||
{- | Applies a function to a specific subtree determined by a list of indices.
|
||||
Unsafe (partial function). -}
|
||||
applyToSubtree :: [Int] -> (Tree a -> Tree a) -> Tree a -> Tree a
|
||||
applyToSubtree [] f t = f t
|
||||
applyToSubtree (i:is) f (Node x xs) = Node x (ys ++ [applyToSubtree is f z] ++ zs)
|
||||
where
|
||||
(ys, z:zs) = splitAt i xs
|
||||
|
||||
{- | Applies a function to a specific subforest determined by a list of indices.
|
||||
Unsafe (partial function). -}
|
||||
applyToSubforest :: [Int] -> ([Tree a] -> [Tree a]) -> Tree a -> Tree a
|
||||
applyToSubforest [] f (Node p cs) = Node p (f cs)
|
||||
applyToSubforest (i:is) f (Node x xs) = Node x (ys ++ [applyToSubforest is f z] ++ zs)
|
||||
where
|
||||
(ys, z:zs) = splitAt i xs
|
||||
|
||||
-- do not delete: find use for
|
||||
--{- |
|
||||
--Applies a function to the first node along a trunk that satisfies a given property.
|
||||
|
||||
Reference in New Issue
Block a user